Writing and Reading Data in ThingSpeak | IoT from Data to Action, Part 2 - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 4:02
Loaded: 4.09%
Stream Type LIVE
Remaining Time 4:02
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 4:02

    Writing and Reading Data in ThingSpeak | IoT from Data to Action, Part 2

    From the series: IoT from Data to Action

    ThingSpeak® is a cloud data service that lets you collect and store data from your devices and then analyze and display the data using MATLAB®. Learn the four basic ways to read and write data for your IoT devices in ThingSpeak:

    1. HTTP(s)
    2. MQTT
    3. MATLAB
    4. Simulink

    Discover how to compare interfaces and choose the right one for your application to read and write data in ThingSpeak.

    Published: 4 Oct 2021

    ThingSpeak lets you collect data, analyze it with MATLAB, and act on the results using alerts, or with interfaces to other web-enabled platforms. In this video, we will cover different ways to write and read data in ThingSpeak.

    We set up an environmental monitor in our first video. Now, we want to get insights from the data. Our first step is to bring the data into ThingSpeak. There are four main ways to write and read data in ThingSpeak.

    To get started using the REST API, create a channel and find the API keys tab. You can test this interface by copying the suggested format into your web browser, including the right API key.

    Let's say a sensor measured the temperature in the room to be 35 degrees. The format for the REST API channel update has three parts-- the base URL, the API key, and the field data. That's the value of 35 you just measured. The final URL looks like this. You can also update multiple fields in the same channel in a single call.

    This number is the number of entries in the channel. Return to your ThingSpeak channel, and you will see this data visible in the field plot. You can read the data back using a similar URL. You'll find more information in the documentation.

    When you are sending data from a device, you write code that will build the URL for each new data point and send it to ThingSpeak continuously.

    If you have an Arduino or Particle device, the ThingSpeak library contains functions to help you write code using the REST API. These illustrate best practices, save you time, and are available on GitHub. Just remember not to update your channel faster than the rate allowed by your license.

    You can use MATLAB to read and analyze your data in ThingSpeak. To get data from the channel, use the ThingSpeak Read function. This code finds the mean of the data, then uses ThingSpeak Write to write the results back to ThingSpeak. You can run the same code in the ThingSpeak interface in desktop MATLAB or in MATLAB Online.

    If your device is in a remote location or has intermittent connectivity, you can use MQTT. Consider a system where a sensor publishes humidity measurements to a topic. Topics are how MQTT organizes data. Another device subscribed to this topic will get humidity data as soon as it gets published. An additional benefit of MQTT is that ThingSpeak saves your device information and lets you manage your devices in the ThingSpeak interface.

    For more complex systems, you may want to simulate your system before you build it. Simulink is a MATLAB-based graphical environment that enables you to simulate a variety of devices. When you run the model, the simulation blocks automatically update fields in the ThingSpeak channel. Once the model is built, you can deploy it directly to the hardware. You can write data to your channels by using the ThingSpeak Simulink blocks that come with the Arduino and Raspberry Pi support packages.

    Now that the data is in ThingSpeak, you can see the instant visualizations on the channel. Use these buttons to edit the plot settings. You now have four ways to write and read data in ThingSpeak. In our next video, we will show you how you can create custom MATLAB scripts for analysis and visualization in ThingSpeak.