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

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
Sample code to retrive last value from Thinkspeak using ESP8266
Avatar
theindianapple
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
April 20, 2016 - 3:20 am
sp_Permalink sp_Print

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 />

 
Avatar
mdahlb

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
2
May 8, 2016 - 12:52 pm
sp_Permalink sp_Print

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.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: jacktheripper125
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

Nsneilotof

angieus2

goldiepw11

BinanceoSt

gnarender123@gmail.com

edenderest

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee