Help using ThingSpeak TimeControl Recurring
Show older comments
Hello:
Using the Timecontrol app, I want to execute a MatlabAnalysis recurring daily at 6:00 A.M. but execute it only ONCE. The MatlabAnalysis code performs a Thingspeakwrite() to a channel. I have the impression that the execution of this code is called multiple times during minute 00. I cannot write to a field more than every 30 seconds i believe. What can I do? Thanks in advance!
Below is my MatlabAnalysis code:
NHRS=6;
disp(['process the last ' num2str(NHRS) ' hours of pool level measurements']);
channelID = xxxxxx;
[data timestamps]= thingSpeakRead(channelID, 'NumPoints', 100, 'Fields', 5);
ts=timestamps;
indx=find(~isnan(data));
data1=data(indx);
ts1=ts(indx);
[N dummy]=size(data1);
[data2]=data1(N-NHRS+1:N);
ts2=ts1(N);
%disp('last 24 pool data levels');
%disp(data2);
disp(' ');
disp('time stamp of last pool level measurement');
disp(ts2);
% Calculate the average
avgValue = mean(data2);
% display the aveage
disp(['mean: ' num2str(avgValue) ' cm']);
% calcul the std deviation
sd=std(data2,1);
%display the std deviation
disp(['sd: ' num2str(sd) ' cm']);
thingSpeakWrite(xxxxxx,[avgValue,sd],'WriteKey','xxxxxx');
1 Comment
Christopher Stapels
on 3 Nov 2026 at 16:12
You should be able to complete your goal with this code and the appropriate timeControl.
What do you mean by "I have the impression that the execution of this code is called multiple times during minute 00" Your code seems fine at first glance, though im nto sure the use of the disp statements will help you when you run the timeControl, except for debug.
Accepted Answer
More Answers (1)
One of two possible issues could trigger the observed behavior. The first would be the TimeControl is using the Recurrence setting on "Hour" instead of "Day". You should not see an "Every" field when select "Day" but is/will be replaced by the "Time" field which should then be 06:00.
Alternatively, you may have a correctly formatted TimeControl, but since ThingSpeak allows up to 12 active TimeControls, it is easy have other schedule daemons left running in the background from prior testing. Select "Apps > TimeControl" and ensure there are not multiple entries for the desired MATLAB app. Delete or make inactive any duplicates that might show up there.
That should prevent the application from being either scheduled multiple times or executing more than once when it is executed/called/scheduled.
I took the liberty of reducing the MATLAB code just a little to eliminate some unneeded temporaries
NHRS=6;
disp(['process the last ' num2str(NHRS) ' hours of pool level measurements']);
channelID = xxxxxx;
[data ts]= thingSpeakRead(channelID, 'NumPoints', 100, 'Fields', 5); % only ts was used, don't need to copy
isOK=isfinite(data); % valid data logical addressing vector
data=data(isOK); % use logical addressing vector directly, no need for find() here
ts=ts(isOK); % ditto for timestamps
N=nnz(isOK); % how many were saved
[data2]=data(N-NHRS+1:N); % NOTE: could replace N here with internal keyword 'end'
ts2=ts(N);
%disp('last 24 pool data levels');
%disp(data2);
disp([newline 'time stamp of last pool level measurement']);
disp(ts2);
% Calculate the average
avgValue = mean(data2);
% display the aveage
disp(['mean: ' num2str(avgValue) ' cm']);
% calcul the std deviation
sd=std(data2,1);
%display the std deviation
disp(['sd: ' num2str(sd) ' cm']);
thingSpeakWrite(xxxxxx,[avgValue,sd],'WriteKey','xxxxxx');
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Birnbaum-Saunders Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!