Hans Scharler
155 views (last 30 days)

ThingSpeak Communication Library for Arduino, ESP8266 and ESP32

Hans Scharler on 17 Aug 2021
Latest activity Reply by Christopher Stapels on 3 Sep 2021

The ThingSpeak Communication Library for Arduino, ESP8266 and ESP32 enables an Arduino or other compatible hardware to write or read data to or from ThingSpeak, an open data platform for the Internet of Things with MATLAB analytics and visualization.

Link: https://github.com/mathworks/thingspeak-arduino

Installation: In the Arduino IDE, choose Sketch/Include Library/Manage Libraries. Click the ThingSpeak Library from the list, and click the Install button.

Compatible Hardware:

  • Arduino/Genuino or compatible using a WiFi Shield
  • Arduino/Genuino or compatible using a WiFi Shield 101 (Use the WiFi101 library version 0.13.0 or older.)
  • Arduino/Genuino or compatible using an Ethernet Shield
  • Arduino/Genuino or compatible using a MKR ETH Shield
  • Arduino MKR1000
  • Arduino MKR1010
  • Arduino VIDOR 4000
  • Arduino GSM 14000
  • Arduino Uno WiFi Rev2
  • Arduino Yún (Rev1 and Rev2)
  • ESP8266 programming directly (tested with SparkFun ESP8266 Thing - Dev Board and NodeMCU 1.0 module)
  • ESP8266 via AT commands
  • ESP32 (tested with SparkFun ESP32 Thing)

Tutorial: https://nothans.com/thingspeak-tutorials/arduino/send-data-to-thingspeak-with-arduino

 
Lauri Matikainen
Lauri Matikainen on 2 Sep 2021

Hello sir,

Where should I move the secrets.h file such as the one for ESP32 https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP32/WriteSingleField

Already checked the instructions at https://www.arduino.cc/en/Guide/Libraries but I cannot find a method to add a bare .h -file (only .zip files).

Christopher Stapels
Christopher Stapels on 3 Sep 2021

The secrets file should be located in then same directory as the .ino file. You can create a new file in the Arduino IDE using the plus button by the tabs near the top.

SHUAI TAN
SHUAI TAN on 19 Aug 2021

Mr Chris,

How do i read a field value at a specific timestamp

 
1 Reply
Christopher Stapels
Christopher Stapels on 19 Aug 2021

The Arduino library doesn't include the ability to read a particular timestamp. We've chosen a reduced number of features to keep the footprint smaller. The best way to achieve the result you are looking for is to use the REST API call for Read Data with the start and end parameters to get the date you are interested in. There is an example in the documentation that shows how to send a REST call but its a POST. You need a GET.

Instead of these lines in that code:

        client.println( "POST /update HTTP/1.1" );
        client.println( "Host: api.thingspeak.com" );
        client.println( "Connection: close" );
        client.println( "Content-Type: application/x-www-form-urlencoded" );
        client.println( "Content-Length: " + String( postData.length() ) );
        client.println();
        client.println( postData );
        Serial.println( postData );

Use something like this, changing the URL for your needs:

url = 'https://api.thingspeak.com/channels/9/feeds.csv?start=2011-11-11%2010:10:10&end=2011-11-11%2011:11:11"
client.println(String("GET ") + url);
SHUAI TAN
SHUAI TAN on 30 Aug 2021

Thank you Chris. you are the best.

 
Christopher Stapels
Christopher Stapels on 17 Aug 2021

Along with some performance improvements, the latest version of the library supports reading from multiple fields of a channel to your device with a single command.

ThingSpeak.readMultipleFields(ChannelNumber);

Related Content

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!