ThingSpeak: How to set 'NumPoints' equal to the maximum available in the channel?
조회 수: 7 (최근 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!
댓글 수: 0
채택된 답변
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
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')
댓글 수: 0
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
참고 항목
카테고리
Help Center 및 File Exchange에서 Read Data from Channel에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!