MATLAB Toolboxes are Now Available on ThingSpeak for IoT Analytics

ThingSpeak offers an easy way to collect data from things, analyze and visualize the data with MATLAB, and act on your data. With MATLAB from MathWorks, you have access to powerful data processing and analysis functions for IoT data. To extend the functionality, we offer toolboxes such as the Statistics and Machine Learning Toolbox™ and Signal Processing Toolbox™. These toolboxes need a license from MathWorks. If you have access to these toolboxes linked to a MathWorks Account, you have access to many of the toolboxes on ThingSpeak. All you have to do is to log in to ThingSpeak using your MathWorks Account credentials. With very little code, it is possible to forecast tidal depths using tide data collected by a ThingSpeak channel and the System Identification Toolbox.

Tide forecasting using MATLAB and ThingSpeak

When you are logged into ThingSpeak using your MathWorks Account, you can use functions from the following toolboxes if you are licensed to use them:

We have created many examples showing you how to use MATLAB Toolboxes using ThingSpeak channel data. We have an example using the Signal Processing Toolbox to Visualize and Remove Outliers in Your Data which a common task when you are working with IoT data from sensors. If you want to forecast environmental data by using a feedforward neural network, we have an example using the Neural Network Toolbox operating on weather station data collected by ThingSpeak. In all of our examples, you are able to use the code right on ThingSpeak and allow it to run on a schedule using TimeControl or be triggered to run using React. Many of your licensed toolboxes are now available with your MathWorks Account on ThingSpeak.

Use MATLAB ‘timetable’ to Merge ThingSpeak Data Channels

We released a new version of MATLAB® and it’s available now for every ThingSpeak user. MATLAB R2016b includes many new features that make it easy to work with time-stamped tabular data, manipulate, compare, and store text data efficiently, and find, fill, and remove missing data.

With multiple sensors around my house or office, I want to be able to send data to multiple ThingSpeak channels. But, when I want to perform data analysis, I have a hard time working with data from multiple channels. The channels do not have the same time stamps and are out-of-sync with each other.

With R2016b of MATLAB, I am able to use the new timetable data container. Once the data is a stored as a timetable, I can perform powerful operations such as retime, synchronize, and rmmissing.

In this example, I have two sensors outside of my office here in Natick, MA. One sensor is a temperature sensor that is sending data to ThingSpeak channel 163540. My other sensor is writing humidity data to channel 163545. Both channels are public. My goal is to plot temperature versus humidity over one time series. To accomplish this, I will use timetable and synchronize inside of a new MATLAB Visualization on ThingSpeak.

% Read from the temperature channel
temperatureTT = thingSpeakRead(163540,'Fields',1,'NumPoints',100,'outputFormat','timetable');

% Read from the humidity channel
humidityTT = thingSpeakRead(163545,'Fields',1,'NumPoints',100,'outputFormat','timetable');

% Synchronize two timestables and fill in missing data using linear interpolation
TT = synchronize(temperatureTT,humidityTT,'union','linear')

% Plot Temperature and Humidity over time
plotyy(TT.Timestamps,TT.Temperature,...
       TT.Timestamps,TT.Humidity);
        
title('Temperature and Humidity Synchronized From Two Channels')
xlabel('Temperature and Humidity in Natick, MA')
legend('Temperature','Humidity')

The first part of the script reads in ThingSpeak data from two different channels and stores the data in two timetables. Once the data is stored in a timetable, I am able to take advantage of synchronize. With synchronize, I can combine both timetables with one time series and fill in missing data using linear interpolation. This results in a plot that shows my data over time without any missing data. To create the plot, I signed into ThingSpeak, selected Apps, and created a new MATLAB Visualization with my MATLAB code.

All ThingSpeak users are able to try this example or explore the other new MATLAB features directly on ThingSpeak. I will leave my temperature (163540) and humidity (163545) channels public, so you can try out timetable example without having to connect devices to ThingSpeak.

Reacting to Events in Your Data With MATLAB

Chris Hayhurst uses a solar water heater at his house to lower energy costs and use hot water in his house heated up by the sun. Chris is a consulting manager for The MathWorks and partnered with the IoT team to use ThingSpeak to collect data about his system and use ThingSpeak’s built-in MATLAB app to analyze it. In this project, Adarsh and I are going to show you how to send alerts when events are detected in the data by using the MATLAB Analysis app.

Solar water heating system

Chris’ home solar water heating system is an example of an IoT application that uses multiple sensors to collect data about a physical system.  Chris’s water heater measures ambient temperature, stored water temperature, collector temperature, and pump speed. All of this data gets collect by ThingSpeak and stored in Channel 29633.

Solar water heater

On days when the stored water temperature exceeds 50°C (122°F), there’s no need to use other methods to heat the store of water to a useful working temperature.  The pump should turn on only when the collector temperature is greater than the temperature of the stored water tank. If the pump turns itself on when the collector is cooler than the stored water temperature, valuable heat is lost from the stored water tank. Chris wants to be alerted of this condition, so that he can adjust the controller settings and increase the efficiency of the system.

IoT systems like Chris’ solar water heating system, typically gather large amounts of data but often the real interest is in events that occur infrequently. The ability to take action when these infrequent events occur is important and requires a mechanism to detect such an event and launch an action. We are going to use the data collected by the solar water heating system stored in the ThingSpeak Channel 29633 and use the MATLAB Analysis app to detect a condition and alert him using Twitter.

solar-water-heater-inside

MATLAB Event Detection

To detect an erroneous pump behavior event, create a new MATLAB Analysis on ThingSpeak with the following code:

% Read data from fields 1, 2, and 3 from channel 26633.
% Field 1 represents the stored water temperature
% Field 2 represents the collector temperature
% Field 3 represents the state of the pump - on or off
[data, time] = thingSpeakRead(29633, 'Fields', [1, 2, 3]);

% Assign measurements to individual variables
storeTemp = data(1);
collectorTemp = data(2);
pumpState = data(3);

% Check if collectorTemp is less than storeTemp
isCollectorCooler = collectorTemp < storeTemp;

% Identify if pump is on while the collector is cooler.
% We apply a logical AND operation to detect an event only when collector
% is cooler than store temperature and the pump is on.
eventDetected = isCollectorCooler & pumpState

Press the ‘Run & Save’ button to save the MATLAB Analysis App. The code above sets eventDetected to 1 every time the collector temperature is cooler than stored temperature and if the pump is on. Now that we can detect the event, we need to set the MATLAB App to be run on a schedule. To do this, we will setup a TimeControl to run our MATLAB code every 5 minutes.

TimeControl options

Sending Alerts using MATLAB Analysis

So far, we’ve created a MATLAB Analysis to detect events in the data being collected in the solar water heater data channel. We associated our MATLAB Analysis code with a TimeControl to have it run every 5 mins to check for our event of interest. To receive a notification via Twitter when the pump is on incorrectly, we can use MATLAB Analysis to send a Tweet.

First, you need to link your Twitter account to your ThingSpeak account. Then, add the following lines of code at the end of your MATLAB Analysis code to send a Tweet when an event is detected:

If eventDetected
webwrite('http://api.thingspeak.com/apps/thingtweet/1/statuses/update',
'api_key', '<ThingTweet_APIKey>', 'status', 'Alert! Solar pump error!')
end

Be sure to replace <ThingTweet_APIKey> with your ThingTweet API Key.

If the solar water heater pump turns on at the wrong times, you will get a Tweet to let you know!

Next Steps

This example shows you the power of some of the ThingSpeak apps that we make available to you to experiment with. The MATLAB Analysis app is really powerful and can be used to detect events in your data and send alerts. MATLAB Analysis can be used for all sorts of calculations and orchestrations of different web services. We could have also used MATLAB to control the pump.

Feel free to try this example and take it further…

  • Reading data from fields in different channels
  • Combining data from fields in a channel and data read from a website such as a weather station or weather forecast.

What will you MATLAB?

Arduino WiFi 101 ThingSpeak Data Uploader Tutorial

Arduino has published a tutorial for their WiFi 101 Shield that sends data to ThingSpeak. The Arduino WiFi Shield 101 is a powerful Internet of Things shield with crypto-authentication that connects your Arduino or Genuino board to the internet using WiFi.

Arduino WiFi 101 ThingSpeak

You only need a few things to build a light and temperature sensor that writes data to ThingSpeak:

  • Arduino Zero or Uno Board
  • Arduino Wifi Sheild 101
  • Photocell
  • Temperature Sensor (This example uses a TMP36)
  • 10K Ohm Resistor

Arduino_WiFi_1010_ThingSpeak

Once you have the circuit built, you create a ThingSpeak channel, connect the Arduino WiFi 1010 to your Wi-Fi network, and install the source code from the tutorial on the Arduino.

Data is now being sent to your ThingSpeak Channel. Go to your channel to see two charts of the light and temperature data. To take the project a step further, go to ThingSpeak Apps and use MATLAB to analyze and visualize and trigger actions from the data.

[via Arduino.cc]

Schedule MATLAB Code with TimeControl

Here at our headquarters we have a weather station collecting lots of weather data and sending it to ThingSpeak. We have made that data public for use in your own projects.

MathWorks Weather Station

We write the temperature and humidity values from the weather station to a ThingSpeak channel. At some point in the project, we started to wonder about dew point calculations. We wrote some MATLAB code that combined the temperature and humidity to calculate dew point. I did this using the ThingSpeak app, “MATLAB Analysis”. You can try this out with ThingSpeak now by signing in, selecting Apps, MATLAB Analysis, New, selecting “Calculate Dew point”, and clicking “Create”. This happens to be one of our built-in examples using our weather station’s public data.

It is great that it was easy to calculate dew point with MATLAB, but I want to see this analyzed data over time just like any other sensor data. The solution is a powerful combination of MATLAB Analysis and TimeControl. We use MATLAB Analysis to do the analysis and write the data to a ThingSpeak channel. Then, we use the TimeControl app to repeat the analysis every 5 minutes.

To setup MATLAB Analysis on a schedule, sign into ThingSpeak, select Apps, TimeControl, and New TimeControl.

Dew Point TimeControl in ThingSpeak

My MATLAB code now runs every 5 minutes doing analysis and writing data to my ThingSpeak channel. The TimeControl settings can be tailored to your needs such as executing MATLAB code once a day or only on weekends. This combination of MATLAB Analysis + TimeControl allows you to create continuous analysis of your project data.

To try this out for yourself, we have a public channel of weather station data that we have collected in Natick, MA at our headquarters. You can use that data and do your own MATLAB Analysis and writing the results back to your own channel. Also, Check out the ThingSpeak Documentation where we have a complete tutorial for you to help get started with ThingSpeak and MATLAB.

[Kickstarter] nodeIT – Small, Stackable IoT Device

Kickstarter projects pop up all of the time. Developers are looking to raise money for their projects so they can order a larger production run and gauge market reaction. A lot of recent projects are trying to address the “Maker Community” by making it easier to prototype connected devices and sensors. We just found one called, “nodeIT” from Sweden.

nodeIT IoT device on Kickstarter uses ESP8266 and ThingSpeak

The nodeIT is centered around the ESP8266 Wi-Fi microcontroller and allows you stack other boards to extend its base functionality. Once the nodeIT is connected to your Wi-Fi network, you can easily publish data to ThingSpeak and visualize the results, such as data collected by a barometric sensor.

For more information about nodeIT, follow their Kickstarter campaign and check out their ThingSpeak Room Monitor project.

[via Kickstarter]

Collecting Dust Levels with ThingSpeak and ESP8266 Wi-Fi

Using the ESP8266 Wi-Fi module, [shadowandy] built a dust sensor to measure dust levels in his house. The project incorporates the Shinyei PPD42NS dust sensor to do the measurements and posts the data to his ThingSpeak channel from data collection and reaction to dust levels.

Dust Sensor sending data to ThingSpeak

The sensor records the PM10 and PM2.5 dust levels to get an accurate indication of the dust in the air. This project is a great example of how a little sensor could turn into something important for protecting machine shops, construction sites, and garages.

[via shadowandy / GitHub]

Soldering Iron Connected to ThingSpeak with #NodeMCU and #ESP8266 Wi-Fi

[Vegard Paulsen] created a solder iron that reports its usage and temperature to ThingSpeak and alerts him when it was left on. He uses an NodeMCU / ESP8266 Wi-Fi module to collect the data and post it to his ThingSpeak channel. Once the data is on ThingSpeak, he is able to send push notifications to his phone using the ThingSpeak React App.

Soldering Iron IoT ThingSpeak

Hackaday.com wrote an article about Vegard’s soldering iron connected to the Internet of Things. Here’s what they had to say:

The data pushes out to the ThingSpeak server which handles pushing data out to the bigger network, and data representation (like the cool Google gauge…). The best part: [Vegard] gets a phone notification when he accidentally leaves his soldering iron on. How perfect is that?

That looks a lot like our desks… wires, microcontrollers, pliers, cutters, Wi-Fi modules, and soldering irons. And now, the soldering iron is on the Internet of Things.

[via Vegard Paulsen / Hackaday.com]

Basement Dehumidifier Tweets Its Humidity with ThingSpeak and ESP8266 Wi-Fi

ThingSpeak user, Spencer, adapted a humidifier that sits in his basement. He is solving a common issue about humid basements. If your dehumidifier fails, you get wet things you have stored and then mold. Spencer created a humidity board using the DHT22 that measures humidity and then reports the data to his ThingSpeak Channel via the ESP8266 Wi-Fi module. Once the data is stored in ThingSpeak, he uses ThingSpeak React to update Twitter when things get out of whack.

Basement Dehumidifier Twitter

[via Twitter]

Let Your Plants Tweet Using Spark and ThingSpeak

Head over to Instructables to learn how to make your plants Tweet using Spark Wi-Fi and ThingSpeak. Gregory Fenton created a project that monitors his plant’s soil moisture and then notifies him via Twitter when it is time to water it.

Spark ThingSpeak Plant Monitor

Greg built the project out of necessity to help his plants suffering from “localized drought”. Let’s hope his plants get proper watering and that other ThingSpeak users can quickly and easily build this project. Thanks for sharing!

[via Instructables]