Main Content

ThingSpeak Read

Read data stored in ThingSpeak channel

Since R2021a

Add-On Required: This feature requires the Embedded Coder Support Package for STMicroelectronics STM32 Processors add-on.

  • ThingSpeak Read block

Libraries:
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32L475VG-Discovery (B-L475E-IOT01A)
Simulink Coder Support Package for STMicroelectronics Nucleo Boards / STM32F7
Simulink Coder Support Package for STMicroelectronics Nucleo Boards / STM32H7
Simulink Support Package for Arduino Hardware / Ethernet Shield

Description

The ThingSpeak Read block reads data from the ThingSpeak™ channel on the ThingSpeak.com website.

ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams in the cloud. You can send data to ThingSpeak from your devices, create instant visualizations of live data, and send alerts using web services. With MATLAB® analytics inside ThingSpeak, you can write and execute MATLAB code to perform preprocessing, visualizations, and analyses.

For more information on how to use ThingSpeak, see Apps, Plugins, or Tutorials.

Limitations

  • The ThingSpeak Write and ThingSpeak Read blocks take a minimum of 700 ms for execution when you run the model in external mode. If the overall model execution time when you run the model in external mode exceeds 2 s, there can be sporadic disconnects. There is no such limitation if you run the model in the Build, load and run mode.

  • When using the WiFi TCP Send, WiFi TCP Receive, ThingSpeak Read, and ThingSpeak Write blocks in a model, the blocks must have the same sample time as the driver code is nonreentrant.

Ports

Output

expand all

At each time step, the port outputs the data read from the field specified in the Field Number parameter.

Data Types: single

The port outputs the status of each read request as mentioned in the following table:

Return status codes

StatusDescription
200OK or Success
-301Failed to connect to ThingSpeak
-303No response/ Unable to parse response from ThingSpeak

Dependencies

This port appears only when you select the Output Status parameter.

Data Types: single

Parameters

expand all

Specify the channel ID from which the block reads data.

If you do not know the channel ID of your channel:

  1. Sign In to ThingSpeak using your MathWorks® Account.

  2. Select Channels > My Channels.

  3. Select the channel from which to read data.

  4. Click the Channel Settings tab.

  5. Copy the channel ID from the Channel ID parameter.

  6. Open the ThingSpeak Read block in your model and paste the copied ID to the Channel ID parameter.

Specify if your channel is private or public.

If you do not know the sharing settings of your channel:

  1. Sign In to ThingSpeak using your MathWorks Account.

  2. Select Channels > My Channels.

  3. Select the channel to get the sharing status.

  4. Click the Sharing tab. Use the option selected in the tab to set Channel Access.

    • Keep channel view private: Set Channel Access to Private. Only you can view the channel data.

    • Share channel view with everyone: Set Channel Access to Public. Anyone browsing the ThingSpeak website can view the channel data.

    • Share channel view only with the following users: Set Channel Access to Private. Users who have access to shared channels can see only the private view of a channel; they cannot add channels, see alerts, or see license information.

Select a field of the ThingSpeak channel from which the block reads data.

When you select the Output Status parameter, the block configures an output port, Status. The port outputs the status message.

Specify how often the block reads data from the ThingSpeak channel.

When you set this parameter to -1, Simulink® determines the best sample time for the block based on the block context within the model.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2021a