Read last value AND time/date from thingspeak | Arduino | 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
Read last value AND time/date from thingspeak
No permission to create posts
May 6, 2016
11:10 am
Avatar
mdahlb

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

Hello,

I'm trying to read the last value AND the date/time from a private channel to my Arduino. I can easily get the last value using the "official thingspeak library for arduino" and the "ReadPrivateChannel"-example. But what about the timestamp (date/time) for that last value? It's not a part of the Thingspeak library I think..

I can access the last value and the timestamp by a get request and get a return in JSON format (this is my privat channel...):

https://api.thingspeak.com/channels/106334/fields/1/last.json?key=J38Y445RB2G9FNL0&timezone=Europe%2FStockholm

 

How do I make my Arduino to "read" this url? I been trying to make a GET request but without any success... =(

 

Regards

Mattias

May 8, 2016
9:15 pm
Avatar
rw950431

Top
Members
Forum Posts: 261
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

Maybe you have to use readRaw() and parse the string yourself?

 From https://github.com/mathworks/thingspeak-arduino/blob/master/src/ThingSpeak.h

/**
* @brief Read a raw response from a public ThingSpeak channel
* @param channelNumber Channel number
* @param URLSuffix Raw URL to write to ThingSpeak as a String. See the documentation at https://thingspeak.com/docs/channels#get_feed
* @return Response if successful, or empty string. Use getLastReadStatus() to get more specific information.
* @remark This is low level functionality that will not be required by most users.
* @code
void loop() {
String response = ThingSpeak.readRaw(myChannelNumber, String("feeds/days=1"));
Serial.print("Response: ");
Serial.print(response);
delay(30000);
}
* @endcode
*/
May 9, 2016
10:20 am
Avatar
mdahlb

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

Thanks!

Well, I managed to get the "age" (in seconds) of the most recent entry by adding the following code:

String response = ThingSpeak.readRaw(myChannelNumber, String(String("/fields/") + String(1) + String("/last_data_age")), myReadAPIKey);
Serial.print("Response: ");
Serial.print(response);

 

So, I get the age in seconds although then I have to convert it into a date and time. Hmm, I would be more convinient if I just could get the time/date at once..

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
13 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

celinabw2, FitoSprayscroma, LunnonGor, lancevl16, bernicenk60, veronicadq18

Administrators: Hans: 387, lee: 457