Visualization shows only the last 8 days

The channel is collecting the data since starting May, but in the visualization i can only see the last 8 days.
What am i doing wrong? see my code below
% Template MATLAB code for visualizing data using the YYAXIS and PLOT functions.
readChannelID = [xxx];
fieldID1 = [1];
readAPIKey = 'xxx';
startTime = datetime(2022,05,02,09,15,00);
endTime= startTime+ days(80);
%% Read Data %%
[data1, time1] = thingSpeakRead(readChannelID,'Field',fieldID1,'dateRange',[startTime endTime],'ReadKey', readAPIKey);
[data4, time4] = thingSpeakRead(readChannelID,'Field',fieldID4,'dateRange',[startTime endTime],'ReadKey', readAPIKey);
%% Visualize Data %%
yyaxis left;
plot(time1, data1,'b');
ylabel('kg Waage');
ylim([22 80 ]);
yyaxis right;
plot(time4, data4,'r');
ylabel('Grad Außentemperatur');
ylim([-60 40]);

 Accepted Answer

dpb
dpb on 9 Jun 2022
Edited: dpb on 9 Jun 2022
'DateRange' Range of data to return
datetime vector
Range of data to return, specified as a comma-separated pair consisting of 'DateRange' and
an array of values that have [startdate,enddate] in MATLAB® datetime values.
ThingSpeak server limits the number of points returned to a maximum of 8000.
Adjust your ranges or make multiple calls if you need more than 8000 points of data.
Doc doesn't say, but given the 8 days it might appear that the 8,000 points returned are the last in the date range given, not the first...
Indeed, testing with the public channel shows that to be the case; you'll have to retrieve subsections in 8,000 sample chunks or not use every point. I didn't read the doc carefully enough to know if can specify discrete times rather than the date range...
>> [data,timestamps] = thingSpeakRead(12397,'DateRange',[startTime,endTime]);
>> whos data
Name Size Bytes Class Attributes
data 8000x8 512000 double
>> timestamps(1)
ans =
datetime
03-Jun-2022 20:37:30
>>
shows it did return last 8000 points.
>> endTime= startTime+minutes(8000); % it's one-minute sample rate; set 8K points
>> [data,timestamps] = thingSpeakRead(12397,'DateRange',[startTime,endTime]);
>> timestamps(1)
ans =
datetime
02-May-2022 09:15:41
>> timestamps(end)
ans =
datetime
07-May-2022 22:34:20
>>
and Voila!!!
ADDENDUM
I'd think it a worthwhile enhancement request for it to return warning about data range and the number of points returned limits....

4 Comments

Thank's a lot for the good analysis.
Does anybody know how to implement "multiple calls" in Thingspeak to overcome teh 8.000-point limit ?
dpb
dpb on 11 Jun 2022
Edited: dpb on 11 Jun 2022
Just write a loop adding whatever is the 8000-pt time differential to the start time.
You'll see the addition of a duration of 8000 minutes in example code; that was the sampling rate of the public channel; use whatever is it for your data source.
I've not used the feature sufficiently to know all the possible ways to address/request data; study the doc to see if there's an alternative to dates to use absolute index values.
Also NB to ensure there's not an "off by one" error in the calculation that may need to adjust for to not have a missing point between calls.
Thanks for taking the time, nice answer! We will consdier adding a note to the doc.
If you are doing multiple calls PLEASE put a small delay between requests, or you will eventually be blocked for abusing the system.
dpb
dpb on 14 Jun 2022
Edited: dpb on 14 Jun 2022
It's in the doc now, but nobody reads the doc first... :)
I'm suggesting it ought to be a warning if the request by date range exceeds the 8k limit that the returned data may (probably/do???) not match the request. readtable has several warnings for example, about variable names and other nits that don't keep it from running as hard errors, but are informational. This would seem to be similar. One can always turn them off if get to be a nuisance I have now done so with the one about names routinely, but it may still be useful for newbies and first-time use for a given file. While now off specific topic of this particular Q?, another enhancement there I think would be for the import options object to have the warning flags state as input so can turn them on/off with it rather than having to code the warning() explicitly every time.

Sign in to comment.

More Answers (0)

Communities

More Answers in the  ThingSpeak Community

Categories

Asked:

on 9 Jun 2022

Edited:

dpb
on 14 Jun 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!