Visualization shows only the last 8 days

4 visualizaciones (últimos 30 días)
Otto Fößel
Otto Fößel el 9 de Jun. de 2022
Editada: dpb el 14 de Jun. de 2022
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]);

Respuesta aceptada

dpb
dpb el 9 de Jun. de 2022
Editada: dpb el 9 de Jun. de 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 comentarios
Christopher Stapels
Christopher Stapels el 14 de Jun. de 2022
Editada: Christopher Stapels el 14 de Jun. de 2022
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 el 14 de Jun. de 2022
Editada: dpb el 14 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Comunidades de usuarios

Más respuestas en  ThingSpeak Community

Categorías

Más información sobre Visualize Data en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by