% Store the channel ID for the sensors channel. channelID = 1517893; % Provide the ThingSpeak alerts API key. All alerts API keys start with TAK. alertApiKey = 'TAKQXKX7Xxxxxxxxxxx'; % 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("Weather Monitoring System Update"); % Read the recent data. temperatureData = thingSpeakRead(channelID,'NumDays',1,'Fields',1); humidityData = thingSpeakRead(channelID,'NumDays',1,'Fields',2); % Check to make sure the data was read correctly from the channel. if temperatureData > 27 & humidityData < 80 fprintf("Sunny day \n") alertBody = "The temperature is above 27°C while the humidity is below 75% which indicates that today is probably gonna be a sunny day."; elseif temperatureData < 27 & humidityData > 80 fprintf("Rainy day \n") alertBody = "The temperature is below 27°C while the humidity is above 75% which indicates that rain is likely to be coming."; elseif temperatureData < 27 & humidityData < 80 fprintf("Forecast \n") alertBody = "The temperature is below 27°C while the humidity is below 75% which indicates that there's a high chance of the weather being overcast"; elseif temperatureData > 27 & humidityData > 80 fprintf("Sunshower \n") alertBody = "The temperature is above 27°C while the humidity is above 75% which indicates that there will probably be a rare weather occurence which is sunshower"; else alertBody = "No data read for today's weather." end % Catch errors so the MATLAB code does not disable a TimeControl if it fails try webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options); catch someException fprintf("Failed to send alert: %s\n", someException.message); end