Thingspeak - status 429 with message "Too Many Requests"

48 visualizaciones (últimos 30 días)
Ajay Kumar
Ajay Kumar el 23 de Dic. de 2021
Editada: Vinod el 23 de Dic. de 2021
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 comentario
Ajay Kumar
Ajay Kumar el 23 de Dic. de 2021
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 :

Iniciar sesión para comentar.

Respuestas (1)

Vinod
Vinod el 23 de Dic. de 2021
Editada: Vinod el 23 de Dic. de 2021
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.

Comunidades de usuarios

Más respuestas en  ThingSpeak Community

Categorías

Más información sobre ThingSpeak en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by