3:20 am

April 20, 2016

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?
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 +="&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 />
12:52 pm


Silver
August 28, 2015

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.
6:59 am

November 11, 2018

10:59 am


Moderators
March 7, 2017

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?
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, winzy99Moderators: cstapels: 460
Administrators: Hans: 405, lee: 457