Hans Scharler

ThingSpeak Communication Library for Arduino, ESP8266 and ESP32

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

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

Suhaila Salaheldin
Suhaila Salaheldin on 21 Sep 2023
Hi,
I have Arduino UNO SMD, how could I connect it to THingSpeak ? which example should i use ??
Thank you
Christopher Stapels
Christopher Stapels on 21 Sep 2023
You will need some way to connect the device to a network. Wi-Fi is probably the easiest and most versatile. There is a Wi-Fi adapter board for UNO or you can use an esp32 to connect the UNO to Wi-Fi. In this configuration, you use serial communication to send data from the UNO to the ESP. Since the ESP32 is about as powerful (or more) than the UNO, my preference is just to use the ESP32 directly and skip the UNO.
DL KA
DL KA on 6 Feb 2023
I have done some basic testing of the ThingSpeak Communication Arduino library with the Raspberry Pi Pico W board using the Philhower Arduino-Pico implementation for Arduino {Arduino-Pico} and it appears to work correctly.
However, there is one complaint generated when building code using the Thingspeak library and that is a warning as follows:
WARNING: library ThingSpeak claims to run on avr, esp8266, sam, samd, esp32, samd_beta, megaavr
architecture(s) and may be incompatible with your current board which runs on rp2040 architecture(s).
To remove this warning, add 'rp2040' to the list of architectures in the "library.properties" file.
munther Aljaf
munther Aljaf on 15 Jun 2022
This reply was flagged by Vinod
hi i was ending data to my channel and then i dont know what happend my channel dosent recive any value plz if u could help me bc my project discussion next week ,if we could speak on e-mail or telegram i apriceat that
Christopher Stapels
Christopher Stapels on 15 Jun 2022
Start a new question on MATLAB answers pelase. You can see the ask a question button if you scroll past the discussion section. Be sure to include your problem description, your hardware, what youve tried, what you observed, and perhaps even a small snippet of the code you think is causing the problem.
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

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);

See Also