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

Avatar

Please consider registering
Guest

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
Avatar
theindianapple
New Member
Members
Forum Posts: 1
Member Since:
April 20, 2016
sp_UserOfflineSmall Offline

Hi,

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: api.thingspeak.com "); 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
Avatar
mdahlb

Silver
Members
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
Avatar
l2ksurf
New Member
Members
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
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

This example (https://www.mathworks.com/help/thingspeak/MoistureMonitor.html) 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:
https://www.mathworks.com/help/thingspeak/readdata.html

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:
https://github.com/nothans/CheerLights/blob/master/FastLED/Arduino_Ethernet.ino

here is a snippet:

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

Does that work for you?

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
11 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:

briskpanda, Dejw0089, Yassine Ben Salah, anis, 43994554AKS, suda

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457