Retrieve value 30 writes ago | 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
Retrieve value 30 writes ago
Avatar
Flying_Dutchman
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
July 5, 2017 - 3:15 pm
sp_Permalink sp_Print

Hi,

on ESP8266 with Arduino, I want to calculate if the temperature went up or down: compare the last write to ThingSpeak with 30 writes ago.

Anybody ideas on if it is possible to pull the last entry_ID and the value of field1 of entryID-30?

Thanks!

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
2
July 6, 2017 - 7:58 pm
sp_Permalink sp_Print

Hi Flying_Dutchman 

In AppsMATLAB Analysis

Run this as is (copy-paste) and see ouput windows

 

% semicolon at the end hides data (not shown)
readChannelID = YoUrChAnNeLnUmBeR0123;
%% Read Data %%
%power = thingSpeakRead(readChannelID, 'OutputFormat','table' , 'NumDays', 3);
%power = thingSpeakRead(readChannelID, 'OutputFormat','table' , 'Numpoints', 30);
power = thingSpeakRead(readChannelID, 'fields',[1] , 'Numpoints', 30)
%% Read Data %%
%disp(power); another way to view data
%% find your Data %%
ulti=power(30) % data of interest
vieji=power(1) % newest data
%% find your Data %%
cono=' ^ up';
if ulti-vieji < 0
cono=' v down';
end
disp(['diff ' num2str(ulti-vieji) cono]) ; % new + or - than old -- your math here
%
% quick & dirty way
%

hope this helps? Smile

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
3
July 7, 2017 - 7:59 am
sp_Permalink sp_Print

If you need to do this client-side and cant run the Matlab script the API can be used

see https://au.mathworks.com/help/thingspeak/get-channel-field-feed.html for the details but the basic API call is something like

https://api.thingspeak.com/channels/9/fields/1.csv?results=30

(You may have to include api_key if your channel is not public).

 

Unfortunately there is no way to only read the 30th value ago on its own.  You can only read all 30 values and pick the one you want.  

Avatar
cstapels

Gold
Forum Posts: 122
sp_UserOfflineSmall Offline
4
July 7, 2017 - 9:22 am
sp_Permalink sp_Print

if you know the entry ID of the last entry, you can subtract 30 and get it like this

GET https://api.thingspeak.com/channels/CHANNEL_NUMBER/fields/FIELD_NUMBER/"+String(entryID-30)+".json";

If you dont know the entry id of the last entry: read the last  entry, the JSON object will return the entry id for you

GET https://api.thingspeak.com/channels/CHANNEL_NUMBER/feeds/last.json

 

The return format is shown here.  I use <ArduinoJson.h> to parse it, there is a bit of overhead with it, but not too bad.

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
5
July 9, 2017 - 8:42 am
sp_Permalink sp_Print

@cstapels- nice..  Is that documented anywhere?

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
6
July 9, 2017 - 8:34 pm
sp_Permalink sp_Print
Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
7
July 9, 2017 - 11:01 pm
sp_Permalink sp_Print

Thanks piajola- its right at the bottom under the heading "Get specific entry in channel" for anyone else who overlooked it.

Forum Timezone: America/New_York

Most Users Ever Online: 114

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

yeseniara11

RomanFug

JamesPes

RobertBak

ScottSmiva

Amourhotte

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee