Commit 250bdc6c authored by robert.sharp's avatar robert.sharp

Upload Matlab Analysis Code

parent 42c82d24
% Store the channel ID for the moisture sensor channel.
channelID = 1563035;
% Provide the ThingSpeak alerts API key. All alerts API keys start with TAK.
alertApiKey = 'TAK66YQB9950YAY8WB7NM';
% 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("Air Pollution information");
% Read the recent data.
pollData = thingSpeakRead(channelID,'NumDays',30,'Fields',1);
% Check to make sure the data was read correctly from the channel.
if isempty(pollData)
alertBody = ' No data read from sensor. ';
else
% Get the most recent point in the array of moisture data.
lastValue = pollData(end);
% Set the outgoing message
if (lastValue>=50 & lastValue < 150)
alertBody = ' Warning: pollution in your area is above a normal level. ';
try
webwrite(alertUrl, "body", alertBody, "subject", alertSubject, options);
catch someException
fprintf("Failed to send alert%s\n",someException.message);
end
end
if (lastValue > 150)
alertBody = ' Warning: pollution in your area is above a toxic level. ';
try
webwrite(alertUrl, "body", alertBody, "subject", alertSubject, options);
catch someException
fprintf("Failed to send alert%s\n",someException.message);
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment