Alerts – Internet of Things https://blogs.mathworks.com/iot Hans Scharler is an Internet of Things pioneer. He writes about IoT and ThingSpeak IoT platform features. Thu, 17 Dec 2020 02:13:31 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 Send Email Alerts from ThingSpeak https://blogs.mathworks.com/iot/2020/01/10/send-email-alerts-from-thingspeak/?s_tid=feedtopost https://blogs.mathworks.com/iot/2020/01/10/send-email-alerts-from-thingspeak/#comments Fri, 10 Jan 2020 14:59:06 +0000 https://blogs.mathworks.com/iot/?p=2685

For this post, I would like to introduce Christopher Stapels as our guest blogger. Christopher builds lots of cool IoT projects and is omnipresent on MATLAB Central and ThingSpeak and MATLAB... read more >>

]]>
For this post, I would like to introduce Christopher Stapels as our guest blogger. Christopher builds lots of cool IoT projects and is omnipresent on MATLAB Central and ThingSpeak and MATLAB questions. He is also the product marketing manager for ThingSpeak and MATLAB hardware here at MathWorks. Welcome to the team!

ThingSpeak has added an alerts API to let you to send emails from your ThingSpeak account. Let me say that again… ThingSpeak now offers email alerts!

Use the new alerts API key to trigger emails and check the sent email history using MATLAB code or another HTTP client.  With MATLAB code in ThingSpeak, you can read and analyze channel values and then respond with an email.  You can even add information in the email about the condition that triggered the email.

My Thirsty Plant

Until recently, you needed a third-party service to get email notifications sent about your ThingSpeak channels.  New in 2020, you can now get email alerts sent to you directly from ThingSpeak.

Regular visitors to the public channel 276330 will be familiar with my desk plant.  I have a soil monitor probe set up to measure the conductivity of the soul, and my plant will send me email if it needs refreshment. I can now have the email set directly from ThingSpeak.  The easiest way is to use a MATLAB analysis.  Here is the general format for sending an email.

Make a MATLAB Analysis to Send Email

  1. First get your ThingSpeak Alerts API key from the Account > My Profile The alerts API key will start with ‘TAK’.
  2. Create a new MATLAB analysis at Apps > MATLAB Analysis. Click the New button on the top. Choose the blank template and with this code.
    alert_body = 'This is the text that will be emailed';
    alert_subject = 'This will be the subject of the email';
    alert_api_key = 'YOUR_API_KEY_FROM_STEP_1';
    alert_url= "https://api.thingspeak.com/alerts/send";
    jsonmessage = sprintf(['{"subject": "%s", "body": "%s"}'], alert_subject,alert_body);
    options = weboptions("HeaderFields", {'Thingspeak-Alerts-API-Key', alert_api_key; 'Content-Type','application/json'});
    result = webwrite(alert_url, jsonmessage, options);
  3. Adjust the alert body, subject and API key.
  4. Click save and Run and you will receive an email within a few moments.
  5. Connect the MATLAB Analysis to a TimeControl or React that depends an a channel value you are interested in.

You can see a more detailed example at Analyze Channel Data to Send Email Notification.  There is even a new template for email alerts in the MATLAB analysis app. You can see all the information on how to send an alert or get your alerts history in the documentation.

Let us know what you think!

]]>
https://blogs.mathworks.com/iot/2020/01/10/send-email-alerts-from-thingspeak/feed/ 15
Don’t Get Stuck in the Mud, Understand Tide Levels with MATLAB https://blogs.mathworks.com/iot/2017/09/14/dont-get-stuck-in-the-mud-understand-tide-levels-with-matlab/?s_tid=feedtopost https://blogs.mathworks.com/iot/2017/09/14/dont-get-stuck-in-the-mud-understand-tide-levels-with-matlab/#respond Thu, 14 Sep 2017 14:25:28 +0000 https://blogs.mathworks.com/iot/?p=2189

Tides go up and down. But, the question is when and how will the tide levels change in the future. If you are planning a boating trip or trying to understand how the wind affects tide levels during... read more >>

]]>
Tides go up and down. But, the question is when and how will the tide levels change in the future. If you are planning a boating trip or trying to understand how the wind affects tide levels during storms, you want to predict the tide levels using data that you have collected locally. In a tutorial published on Hackster.io, you will be able to learn how to use ThingSpeak to collect sensor data that represents the tide height at a given time, use MATLAB to preprocess the data, use MATLAB to predict future tide levels, and use ThingSpeak to send alerts. Here’s what the system looks like installed at a dock in Cape Cod.

The tide height is calculated using an ultrasonic level sensor. This measurement is taken periodically and then sent to ThingSpeak, an IoT analytics cloud platform by MathWorks, using a cellular modem. The system can easily be adapted to collect data about any environmental system such as greenhouses or oyster farms.

Once you have the data in a ThingSpeak channel, you use MATLAB to preprocess and clean up the data. The raw data some times has extraneous values caused by environmental factors such as lighting, cabling, and electrical interference. Sometimes, you have missing data caused by connectivity issues. It is important to clean up the data before you use the data in your analysis.

To predict future tide levels and send alerts when the tide is rising or falling, we use the MATLAB Analysis app on ThingSpeak. With MATLAB, we can use historical data to make a prediction about the future tide levels. This predicted tide level can be used to help schedule a boating trip or plan for a water surge after a storm.

 

Tide Alerts

Remembering to check the tide level when fishing or lazing on the beach is not particularly convenient. A much more useful approach is to have the system send a message when the time has come to pack up and start heading back to the dock. The timing of the alert depends on how much water depth is needed by a particular boat. Larger boats need higher water levels in order to move without getting stuck in the mud. One way to send alerts is to use ThingSpeak and MATLAB to detect changes in tidal height and send alerts.

Conclusion

Developing a tide monitoring system provided accurate tide level measurement and tide level prediction, with the added ability to send alerts. Robert has been able to avoid being stuck in the bay by providing enough time to get back to his dock using this system. This project also serves as a useful approach to solving many data-driven puzzles by having a reliable way to collect, analyze, and act on data. Using MATLAB, the accuracy of the tide levels improved by understanding the proper tide levels at a specific location and when the tide levels will change. If you used the general tide forecast, you would have to account for several inches of tide height difference.

Resources

]]>
https://blogs.mathworks.com/iot/2017/09/14/dont-get-stuck-in-the-mud-understand-tide-levels-with-matlab/feed/ 0