My project for Arduino Day 2019 is an autonomous sensor device that reports its battery status to Amazon Web Services. It uses AWS for data insight, graphs and to indicate how long it's expected to continue living without charging. It raises an email alarm at near death.
This post shows the AWS modules used to store, report and mail, and how they interact. |
The connectivity to AWS - safe, with certificate authentication - is covered in its own blog post.
The activities I explain here are:
- Receive metrics from Arduino
- Enrich the data, add calculations for reporting and alerting
- Store the enriched data
- Report and Graph on the stored data
- Alert on low battery
Receive
In this part, the data arrives in the AWS domain
The messages from the Arduino arrive in the AWS IoT Core module, on the MQTT server, as a JSON payload
If we don't do anything, the data will get lost. We'll use rules in the same module to decide what to do with the data.
Enrich
In this part, we calculate the timestamp of arrival and the active time left in the battery.
A rule subscribes to the MQTT topic. It uses SQL to calculate additional info.
That data is then sent onwards for the two different functions:
- to AWS IoT Analytics for data collection
- to a new MQTT topic, to prime the alerting functions.
Store
In this part, the enriched data is sent ot AWS IoT Analytics, where it is stored for later reporting.
AWS has several storage options. I'm using a data set in the IoT Analytics module here.
The rule from the previous section streams the data, via a data channel, to the data set.
It's stored here for as long as you define, and can be used in the reporting module later on.
You can configure the refresh rate of the data set. If you don't set that up, refresh can be done from the web console.
MQTT messages are volatile. If you want to work with your gizmo's data later on, take care to use one of the AWS services to persist it.
Report and Graph
In AWS Quicksight, I retrieve the data from IoT analytics. It can be presented, analyzed and shared in various formats.
While most of the other modules get data pushed, the reporting module pulls data from the IoT Analytics data set.
You can create dashboards, snapshots, etc...
The capture below shows the battery charge % over time, and a silly pie chart with number of messages per charge %.
Alert
The AWS SNS (Simple Notification Service) can send push notifications.
It supports messages to a phone, mails and (also external) web services.
I set up an sql filter in IoT Core to only call a rule when the battery authonomy is below 1 day.
When that rule is triggered, it sends the MQTT payload to an SNS topic.
In SNS, I subscribe to that topic The subscription is configured to shoot a mail to my personal mailbox.
I selected RAW format when moving data to SNS. That's why you see the raw payload in the contents.
Tutorials
If you want to make a similar setup, you can check these tutorials and how-to's:
image: tutorial map
- red area -connect: Arduino MKR WIFI 1010 and Amazon Web Services: Safe MQTT with SSL and Certificate
- yellow area - receive and report, subscription required: IoT Foundation: Telemetry and Internet of Things Foundation Series
- green area - alert: Set Up Email Alerts
Try it!
Top Comments