Sample code to retrive last value from Thinkspeak using ESP8266 | ESP Wi-Fi | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Sample code to retrive last value from Thinkspeak using ESP8266
No permission to create posts
April 20, 2016
3:20 am
New Member
Forum Posts: 1
Member Since:
April 20, 2016
sp_UserOfflineSmall Offline


I am new with Arduino & esp8266 and using the below code to upload data to ThinkSpeak. Everything works fine, but now I want to retrieve some data back from ThinkSpeak. Can some one help in developing the code for retrieval?

// Using XXXXX here as my channel is private

From what I am checking, I have to use the above GET string to get the fields data. But I don't know how to create the request string.

Help would be appreciated. Thanks

// Uploading data to Thinkspeak<br />uploadData() { String apiKey = "ESDS8678890SDDS"; String myData = "45.5"; // example of data to send if (espClient.connect(server,80)) { String postStr = apiKey; postStr +="&amp;field1="; postStr += String(myData); postStr += " "; espClient.print("POST /update HTTP/1.1 "); espClient.print("Host: "); espClient.print("Connection: close "); espClient.print("X-THINGSPEAKAPIKEY: "+apiKey+" "); espClient.print("Content-Type: application/x-www-form-urlencoded "); espClient.print("Content-Length: "); espClient.print(postStr.length()); espClient.print(" "); espClient.print(postStr); Serial.print(postStr); Serial.print("My Data: "); Serial.print(myData); Serial.print(" "); } espClient.stop(); }<br /><br />

May 8, 2016
12:52 pm

Forum Posts: 10
Member Since:
August 28, 2015
sp_UserOfflineSmall Offline

If you just want to retrieve the last value for a channel you could use the official thingspeak/arduino library. That works fine. But if you also would like the date/time for the last value I don't think you could use that library. I'm having the same problem, I would like to get the timestamp for the last value as well.

November 11, 2018
6:59 am
New Member
Forum Posts: 2
Member Since:
November 11, 2018
sp_UserOfflineSmall Offline

Im having the same problem now! Any of you found any solution?! Thank you!

November 12, 2018
10:59 am

Forum Posts: 885
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

This example ( shows how to use a POST to update your channel, and includes a function to get the response form ThingSpeak. The response includes the present time.

You can also use this code to get the response from a read data request:

But as the post above says, the ThingSpeak Communication Library is the easiest way.

This page has a function that shows how to use a GET from a device to get data:

here is a snippet:

client.println("GET /channels/"+tsChannel+"/field/"+tsField+"/last.txt");

Does that work for you?

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

huldacormier, bogart, estebanmateo93, mikewrite, onlinebusiness, winzy99

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457