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

6 ビュー (過去 30 日間)
Luke Martin
Luke Martin 2021 年 11 月 16 日
回答済み: Rogier 2022 年 7 月 13 日
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 コミュニティ

カテゴリ

Help Center および File ExchangeRead Data from Channel についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by