ThingSpeak: How to set 'NumPoints' equal to the maximum available in the channel?

12 次查看(过去 30 天)
Hi folks,
I'm looking for a way to set the '2733' in my command below equal to the amount of datapoints available.
[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 2733, 'ReadKey', readAPIKey);
For context, I'm trying to setup visualisations that still work when the dataset in the channel is changed. For my current dataset, I have 2733 lines so the above works, but I'd like to get it to the point where it can work without amendment when I change the dataset.
Thanks!

采纳的回答

Vinod
Vinod 2021-11-16
See this documentation. The NumPoints can be at max 8000. If you have less than 8000 points in your channel, everything is returned. If you have >8000 points, only the most recent 8000 are returned.
I'd recommend also answering this survey from the developers as they are looking to provide functionality based on use cases.

更多回答(1 个)

Rogier
Rogier 2022-7-13
I have written this bit of code to help with this problem for myself, figured I'd share
% Channel to read from
readChannelID = 123456789;
% Set these to start & end of the data you're interested in
startDate = datetime('2022-07-06');
endDate = datetime('now');
% How often data is logged, max. This example is once per minute.
% If you don't know exactly, make sure this is higher. So if it
% is roughly once a minute, but can sometimes be twice a minute for
% a bit, be safe and set to '2' and 'minute' for twice a minute.
frequencyTimes = 1;
frequencyPer = 'minute'; % can be 'year', 'month', 'day', 'hour', 'minute', 'second', or 'millisecond'
% Example of output data
total = 0;
% Leave this block alone
rangeEndDateNum = addtodate(datenum(startDate), 8000 / frequencyTimes, frequencyPer);
rangeEndDate = datetime(rangeEndDateNum, 'ConvertFrom', 'datenum');
dateRange = [startDate, rangeEndDate];
diff = rangeEndDate - startDate;
while dateRange(1) < endDate
if dateRange(2) > endDate
dateRange(2) = endDate;
end
% Retrieve data
[data, time, info] = thingSpeakRead(readChannelID, DateRange=dateRange);
% Do something with data
numberOfElements = numel(time);
% Accumulate with previous data
total = total + numberOfElements;
% This sets up the next chunk
dateRange = dateRange + diff;
end
% Do something with the accumulated data
display(total, 'Total number of datapoints in ThingSpeak channel')

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Read Data from Channel 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by