Jonas Meier in MATLAB Answers
Última actividad el 23 de Feb. de 2024

Dear all, once per month I want to send an email with selected data from thingspeak. TimeControl only offers up to weekly but not monthly. Do you have Tipps?
guy caluwaerts in Discussions
Última actividad el 21 de Dic. de 2023

I want to control the level my water tank with a esp8266 and Thingspeak. I can see the level in Thingspeak. This is working. Now I want to send 2 emails : One daily email with the actual level Alarm email when level is below a setpoint. How can I incorporate the value from a channel in the email ? What I have now for the daily email , but with errors : alert_body = 'huidig peil regenput'; channelID = ..........; % Provide the ThingSpeak alerts API key. All alerts API keys start with TAK. alertApiKey = 'TAK...............'; % Set the address for the HTTTP call alertUrl="https://api.thingspeak.com/alerts/send"; % webwrite uses weboptions to add required headers. Alerts needs a ThingSpeak-Alerts-API-Key header. options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]); % Set the email subject. alertSubject = sprintf("Niveau regenput " ); % Read the recent data. peil = thingSpeakRead(channelID,'Fields',1); % Check to make sure the data was read correctly from the channel. % Set the outgoing message webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil); % Catch errors so the MATLAB code does not disable a TimeControl if it fails try webwrite(alertUrl , "body", alert_body, "subject", alertSubject, options); catch someException fprintf("Failed to send alert: %s\n", someException.message); end The errors I receive : Unrecognized function or variable 'alert_Body'. Error in Read Channel to Trigger Email 1 (line 24) webwrite(alertUrl , "body", alert_Body, "subject", alertSubject,"Fields",peil); Manny thanks in advance Send email with the value of a channel MATLAB is case sensitive. alert_body is not equal to alert_Body Be careful with daily emails, you are limited to 800 yearly alert emails. (but there are enough for one per day or more) Your code example shows how to put a channel value in the email. peil = thingSpeakRead(channelID,'Fields',1); % Check to make sure the data was read correctly from the channel. % Set the outgoing message webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil); This will make the subject equal to the value from field 1 Hi Christopher, I did the notification and don't receive no errors anymore. Unfortunately I also don't receive the emails in my mailbox. % webwrite uses weboptions to add required headers. Alerts needs a ThingSpeak-Alerts-API-Key header. options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]); % Set the email subject. alertSubject = sprintf("Niveau regenput " ); % Read the recent data. peil = thingSpeakRead(channelID,'Fields',1); % Set the outgoing message try webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil); end Check your junk folder and make sure you arent blocking thingspeak.com at your email server. You can also take the try ..end.. syntax off, and remove the semicolon on the webwrite line to test and make sure the command was sent. What do you mean with junk folder ? When I do save and run I receive 2 messages. MATLAB code ran successfully. Failed to send alert: The server returned the status 401 with message "" in response to the request to URL https://api.thingspeak.com/alerts/send. 401 means unauthorized. Check your alerts api key. By junk folder i menat for email, but its clear its not sending. I copy past het API key again but no result. does the api key begin with TAK? yes. I use the alertapikey alertApiKey = 'TAKMAxjn5Ad1TrzrNWH'; I also renewed already the key, but no result. You are forgetting the options when you webwrite. Thats why its 401 unauthorized. No key included with the requiest. webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options); webwrite(alertUrl , "body", alertBody, "subject", alertSubject, peil, options); doesn't work webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options); Was sending an email once, but without the value of channel 1 Afterwards I received the message when I run the app : "Failed to send alert: Each postName must be given a corresponding postValue." where can I find the documentation about sending information by email ? All the examples I can find only describe the software for the arduino or esp8266/32 https://www.mathworks.com/help/thingspeak/alerts-api.html and https://www.mathworks.com/help/thingspeak/sendalert.html I reccomend you start with the example code and try to modify it one part at a a time. This example is independant of the devece. I would start here. https://www.mathworks.com/help/thingspeak/analyze-channel-data-to-send-email.html My soil moisture cannel doesnt have good data anymore, but you can tie it to the traffic 38629 or weather 12397 channels at ThingSpeak for testing. In the example, you can add the moisture data to the alert body variable to bet information sent to you. I started from these exemples and could send emails but after I tried to include to value of channel 1, I don't receive emails anymore and receive error messages when I run the timecontrol app without to make any changes. I still struggle with my originale question how to include the value of a channel in the body of the email. Christopher, I followed this example. You only send an email with text. I want to send text + the last value from channel 1. What is working for the moment: 1. sending text with : alertBody = 'huidig peil regenput :'; 2. Sending value of channel 1 : alertBody = thingSpeakRead(channelID,'Field',1); What is not working is the combination of both. It must be something like this, but this syntax is not accepted : alertBody = ('huidig peil regenput :' ,thingSpeakRead(channelID,'Field',1)); try seperating the actions. bob = thingSpeakRead(channelID,'Field',1)); % assumes data is numeric, otherwise use 'outputformat','timetable' alertBody = "The value of my field is " + bob; email timecontrol
Don in Discussions
Última actividad el 5 de Jul. de 2023

I am remotely monitoring solar energy. My monitors shut off at night to conserve battery power, ending data being sent to ThingSpeak, which is fine. I do want to be alerted quickly though during the day when data should be coming in. How can I do this? ReAct doesn't have any way to limit when actions will happen and TimeControl doesn't seem to be able to only perform during certain hours either. I've looked for examples where Matlab analysis might perform a task between certain hours but can't seem to find anything. FWIW, an email would be the preferred method of alert. ThingSpeak React (or similar) needed for NoData, but only during certain hours. MATLAB analysis is the way to go. You can trigger the analysis from a regular time control but start the code with a check on the time. (datetime('now')) If the time is in the range you want, run the check for data. If the time is outside working hours, exit gracefully and nobody gets upset :) There are a few good ways to check for missing data. e.g. There is a last update age API that will give you the age of the most recent post (age=webread(url)). Or you can just read the last n points with thingSpeakRead and look at the timestamp. There is a template to generate email alerts in ThingSpeak in MATLAB analysis, or you can see similar code here. Here is the alerts doc. Here is the specific page on send alert. react time control no data
Joseph in Discussions
Última actividad el 15 de Mayo de 2023

Up until yesterday (May 6, 2023), time controls were working fine in regards to running my Analysis code recurring at specified intervals. Now they will no run more than once? I’ve tried creating new time controls but no luck. I have to manually run the code to get updated results. Time Controls not working? There was a rare short outage, first one ive seen in 6 years. Things should be fine now, please post here if you are still having trouble. time control
Tobias Wagner in MATLAB Answers
Última actividad el 10 de Nov. de 2022

Hi everybody, I have successfully created a thinghttp that returns a number. It's running with time control. How can I write the number to a thingspeak channel?
Martin in Discussions
Última actividad el 19 de Sept. de 2022

Help us please, we need to send email after measurement from sonde (GSM report) is under limit for three days. "React" on the limit, is non for three days under limit., and time control is days or weeks runner. I propose trigger on time control but what is the code? ???? % Read the recent data. moistureData = thingSpeakRead(channelID,'NumDays',3,'Fields',1); {is that right, that I read last three days measurement (3000x)?} % Check to make sure the data was read correctly from the channel. if isempty(moistureData) alertBody = ' No data read from plant. '; else %{need if % moistureData is for three days under limit from sonde then send % email} span = max(moistureData) - min(moistureData); dryValue = span; % Get the most recent point in the array of moisture data. lastValue = moistureData(end); % Set the outgoing message if (lastValue<=dryValue) alertBody = ' I need water! '; elseif (lastValue>dryValue) alertBody = ' No water needed. '; end really thanks so much Email notification after 3 days drying plant Im sorry, im not quite clear on your question. Can you try to simplify what you need? Perhaps describe what will happen if you get the correct code set up. thanx for reply, what i need is code for this> if for three days is received data {gprs upload} under "limit" {integer, change constant}, then send email. How may I do this please? If all the points for the last three days are under the limit, then send the alert? I would calculate the max in the three days. If max is less than your limit, then all three days must be. There is already code in what you shared above to calculate the maximum value. let me ask you: is that right moistureData = thingSpeakRead(channelID,'NumDays',3,'Fields',1); the code read every data from fields1 for last three days? and please, how to send this max value in the email? really thank you, Martin yes, that should work to get 3 days of data as long as there are less than 8000 points in those three days. To send the max valuie in the email, add it to the variable alertBody. timecontrol

Acerca de ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.