Read last value AND time/date from thingspeak | Arduino | 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
Read last value AND time/date from thingspeak
Avatar
mdahlb

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
1
May 6, 2016 - 11:10 am
sp_Permalink sp_Print

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

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
2
May 8, 2016 - 9:15 pm
sp_Permalink sp_Print

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
*/
Avatar
mdahlb

Silver
Forum Posts: 10
sp_UserOfflineSmall Offline
3
May 9, 2016 - 10:20 am
sp_Permalink sp_Print

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:
16 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:

winnieeq69

AutoCheernpen

Bostermet

engladNed

iivenul

olewaeayafaku

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee