Thingspeak - status 429 with message "Too Many Requests"

조회 수: 54 (최근 30일)
Ajay Kumar
Ajay Kumar 2021년 12월 23일
편집: Vinod 2021년 12월 23일
Basically, I am getting temperature values and trying to send an email alert whenever the temperature exceeds a specific point.
But however the code runs but yet I am facing an error that says
Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray (line 373)
The server returned the status 429 with message "Too Many Requests" in response to the request to URL https://api.thingspeak.com/alerts/send.
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webwrite (line 139)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in Customer Temperature Email Trigger (line 10)
webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
I am also attaching the code.
channelID = 1614947;
alertApiKey = 'PRIVATE_ALERT_API_KEY';
alertUrl="https://api.thingspeak.com/alerts/send";
options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]);
temperature = thingSpeakRead(channelID,'NumDays',30,'Fields',1);
recentvalue = temperature(end)
alertSubject = sprintf("Temperature Alert");
alertBody = sprintf(" The temperature of the customer entering the store is high : ",recentvalue);
if recentvalue > 32
webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
end
Basically the other articles tell me that I have to enter a delay or a pause because the free version of thingspeak has limitations. Any idea on what I could do to make sure the code runs with minimal amount of delay?
  댓글 수: 1
Ajay Kumar
Ajay Kumar 2021년 12월 23일
Further update,
I have gone through all the documentation but they do not explicity mention on if we can add delays or pauses or any code to prevent the code from throwing Error 429. Is it possible that the field chart on thingspeak I am plotting my temperature points on is the reason for this?
Source :

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

답변 (1개)

Vinod
Vinod 2021년 12월 23일
편집: Vinod 2021년 12월 23일
Did you read the note on the help page that says "Users are limited to 2 alerts every 30 minutes. The rate limit is applied when the request is made, not when the email is sent. If you exceed the request limit, the API returns the response code 429"?
How often is your MATLAB code executing? If it is more than twice every 30 minutes, it is expected that you will get a 429 code. If your temperature is likely to exceed that limit, one way is to try-catch the call to webwrite so the 429 is handled gracefully by your code.
channelID = 1614947;
alertApiKey = 'YOUR_ALERT_API_KEY';
alertUrl="https://api.thingspeak.com/alerts/send";
options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]);
temperature = thingSpeakRead(channelID,'NumDays',30,'Fields',1);
recentvalue = temperature(end)
alertSubject = sprintf("Temperature Alert");
alertBody = sprintf(" The temperature of the customer entering the store is high : ",recentvalue);
if recentvalue > 32
try
webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
catch
% Code execution will end up here when a 429 is caught
end
end
The above solution may be OK for your application, or, you may want more frequent alerts which the above try-catch will skip over. In this case you can use webwrite with a service like www.pushingbox.com and use that service to send the alerts.

커뮤니티

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

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by