필터 지우기
필터 지우기

I want to rewrite this code that it keeps looping so when the channel 1 data reaches the threshold level, it automatically sends an alert but I also need it to stop sending if

조회 수: 1 (최근 30일)
% ThingSpeak Channel ID and Read API Key for the channel you want to monitor
channelID = 2226948; % Replace with your actual ThingSpeak Channel ID
readAPIKey = 'T9OH3JOE1B5WT1SU'; % Replace with your actual ThingSpeak Read API Key
% Field ID for the channel you want to monitor (e.g., Field 1)
fieldID = 1;
% Threshold value for the channel
threshold1 = 100; % Your threshold value for the channel
threshold2 = 200;
threshold3 = 300;
% Read the latest data from the specified channel and field
try
% Read the latest entry from the specified field
response = thingSpeakRead(channelID, 'Fields', fieldID, 'NumPoints', 1, 'ReadKey', readAPIKey);
% Extract the latest data point from the response
latestData = response(end, fieldID);
% Call SMS integration function
if latestData >= threshold1 && latestData <= threshold2
sendMessage('+639319217695,+639105034409', 'Threshold exceeded in Yellow!');
elseif latestData >= threshold2 && latestData <= threshold3
sendMessage('+639319217695,+639105034409', 'Threshold exceeded in Orange!');
elseif latestData >= threshold3
sendMessage('+639319217695,+639105034409', 'Threshold exceeded in Red!');
end
catch
disp('Error retrieving data from ThingSpeak'); % Handle data retrieval errors here
end
function sendMessage(number, message)
% Replace with your SMS service API endpoint and API key
apiUrl = '- - - - -';
apiKey = '- - - - -';
% Compose the message payload
payload = struct('apikey', apiKey, 'number', number, 'message', message);
try
% Send the SMS using the SMS service API
response = webwrite(apiUrl, payload);
% Process the response as needed
disp('SMS sent successfully');
catch
disp('Error sending SMS');
end
end
  댓글 수: 1
Rainer Gerald
Rainer Gerald 2023년 9월 14일
I want to rewrite this code that it keeps looping so when the channel 1 data reaches the threshold level, it automatically sends an alert but I also need it to stop sending if the first alert level has already been reached.

댓글을 달려면 로그인하십시오.

답변 (1개)

Christopher Stapels
Christopher Stapels 2023년 9월 14일
이동: Christopher Stapels 2023년 10월 17일
That is also I problem Ive had. When you send an alert, you can write to another channel a message sent flag and read that channel before you decide to send the email. Then just remember to write the flag back to sero once you acknowledge the alert or the threshold is no longer crossed.
Another way to do it is to use time. i.e. If you check the threshold evey five minutes, then check the time, if its ten minutes (or more) after the threshold was crossed, then assume the alert was sent last time.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 REST API에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by