Thingspeak - status 429 with message "Too Many Requests"
Show older comments
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 Comment
Ajay Kumar
on 23 Dec 2021
Answers (1)
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.
1 Comment
Joseph
on 11 May 2025
Hi Vinod, I am trying to set up a system to send notifications if my float switches are pressed (indicating the water level in a fish tank is low). My ThingSpeak React and MATLAB analysis worked when I inserted the "try" and "catch" functions are you recommended above, thanks!. However I will probably need more the two email alerts every 30 mins; is this the limit for paid version of ThingSpeak? Is so, how can I webwrite to www.pushingbox.com ?
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Read Data from Channel 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!