This is a presentation I recently presented to the Brisbane AWS User Group.
"AWS is a standard place to do business, but it can also be used for fun. Mark runs us through a recent project leveraging AWS IoT, Cognito, S3, DynamoDB, a sensor or two and his plants(?!).
Come and see how easy it is to innovate on AWS and have a working solution in a short space of time."
9. The Choice was EASY!
We already know I chose
automation.
Next, project planning;
What technology and
hardware to use...
10. Project Planning
As per all my well thought out projects, I needed a 3 step plan.
Step 1
I know AWS.
I’m going to use AWS.
IoT everything!!!
Step 2
Acquire the hardware.
Assemble the hardware.
Plug it in.
Step 3
Watch my plants live
on!
11. ● AWS Managed Service
● Built-In Integrations with other AWS services
● Highly Scalable to billions of devices
● MQTT & Websockets
● Cost effective
● Rule Engines
AWS IoT
The Workhorse...
12. ● WiFi 802.11b/g/n enabled development board
● USB interface
I decided to flash the firmware with Mongoose OS
● Web-based IDE
● Over-The-Air Updates
● Javascript & C/C++
● Built in support for AWS IoT & MQTT
● https://mongoose-os.com/
NodeMCU ESP8266
A brief overview of the hardware I used...
13. ● Soil Moisture Sensor
● 12v Peristaltic liquid pump
● Water tubing
● Reservoir
● Wires
Purchased in minutes from:
Sensors & Equipment
A brief overview of the hardware I used...
15. I Needed Objectives!
Moisture
Tracking
I need to track the plant
moisture.
1. Get the data
2. Send the data!
Notifications Automated Watering
I need to know if the plant is
dry.
If sensor reading is less than
dryness threshold => ALERT!
Fix the problem!
If dry,
1. Issue Watering Command
2. Water the Plant
Extensibility
Ability to grow, extend and
scale my solution.
No better place than on
AWS for this :)
16. My High Level
Architecture
Sneak peak of final state…
No good project can exist
without a quick but helpful
AWS architecture diagram!
18. The NodeMCU
arrived first!
Import The Libraries
Connect to MQTT topics
Send the Sensor Data!
Flash the Hardware
In short, it was time to get
coding!
19. Code Overview
IoT device code written in
javascript!
Full-stack JS anyone?
Import the Libraries
Publish the data via
MQTT
Read from the sensor
Connect to WiFi
Connect to MQTT
22. Time to process
the data!
AWS IoT Rules, here I come!
To act on the data, you define Rules:
● They are analysed based on MQTT topic
● Actions are performed if the rule’s condition is met
Actions give IoT devices the ability to interact with AWS
services:
AWS IoT Rules Engine
And many more!
23. My AWS IoT Rules
Storage
Data flows straight into a
DynamoDB table!
1. Get the data
2. Store the data!
Notifications Automated Watering
I need to know if the plant is
dry.
If sensor reading is less than
dryness threshold, send alert via
Amazon SNS
IoT Rules action the response!
If dry,
Publish Watering Command to
device control MQTT topic.
Extensibility
Ability to grow, extend and
scale my solution.
So many options...
24. So Why DynamoDB?
● Fast, Consistent Performance
○ Single-digit millisecond responses
● Fully Managed NoSQL database service
● Document and Key-Value store
● Highly Scalable
○ use AWS AutoScaling!!
● Highly Available
● Cost effective
25. DynamoDB Table
Setting up my DynamoDB table was easy!
Table Name: plant_monitor
Partition Key: plant (String)
Sort Key: time_recorded
(Number)
26. Data Storage Rule
The AWS IoT Rule to store my data was simple!
Rule Query Statement:
SELECT topic() AS plant, timestamp() AS time_recorded,
* FROM 'plant/esp8266_4335FE'
Target:
30. My simple serverless website.
Website Hosting
Stored, deployed and
hosted my static website
using Amazon S3.
So scalable, so simple.
AWS SDK Authentication
“for Javascript in the Browser”
Used for AWS calls to Amazon
Cognito and DynamoDB.
Amazon Cognito for user
Authentication.
Amazon Cognito gives the
user IAM credentials to access
the DynamoDB table.
Data Source
We’re storing the data in
DynamoDB.
I just queried and retrieved
the relevant data...
31. What is Amazon Cognito?
● Fully Managed Authentication Service
● Secure, Scalable User Directory
● Social and enterprise identity federation
○ i.e. Google, Facebook, Amazon
● UI for integration into your app
● Provides IAM access control for AWS resources
○ e.g. allow authenticated users of your application to retrieve data
from DynamoDB
32. Graphs!
Once I had the data, I passed
it into Chart.js...
Those drops in the dryness is
where I watered my plant!
33. My Growing
Architecture
A quick recap of where we
are up to:
● IoT Core & MQTT
● Pushing Sensor Data
● IoT Rule => DynamoDB
● DynamoDB
● Amazon Cognito
● S3 Static Website
34. First Objective Down!
Moisture
Tracking
I need to track the plant
moisture.
1. Get the data
2. Send the data!
Notifications Automated Watering
I need to know if the plant is
dry.
If sensor reading is less than
dryness threshold => ALERT!
Fix the problem!
If dry,
1. Issue Watering Command
2. Water the Plant
Extensibility
Ability to grow, extend and
scale my solution.
No better place than on
AWS for this :)
36. ● Amazon Simple Notification Service (SNS)
● Fully managed AWS notification service
● Pub/Sub Messaging
○ Push messages to
■ Amazon Simple Queue Service (SQS)
■ AWS Lambda functions
■ HTTP(S) endpoints
● Mobile push notifications and SMS
Time for Amazon SNS
It does what is written on the tin in the docs...
38. My Growing
Architecture
A quick recap of where we are
up to:
● IoT Core & MQTT
● Pushing Sensor Data
● IoT Rule => DynamoDB
● DynamoDB
● Amazon Cognito
● S3 Static Website
● IoT Rule => SNS
● Amazon SNS
39. Second Objective Down!
Moisture
Tracking
I need to track the plant
moisture.
1. Get the data
2. Send the data!
Notifications Automated Watering
I need to know if the plant is
dry.
If sensor reading is less than
dryness threshold => ALERT!
Fix the problem!
If dry,
1. Issue Watering Command
2. Water the Plant
Extensibility
Ability to grow, extend and
scale my solution.
No better place than on
AWS for this :)
41. Additional AWS IoT Rule
The AWS IoT Rule to check my plant dryness and invoke
publish back a message to my plant!
Rule Query Statement:
SELECT topic() AS plant, * FROM 'plant/esp8266_4335FE'
WHERE sensorValuePercentage > 90
Target:
42. Lambda Function
I wanted to publish a different response message to
another MQTT topic, so I opted for Lambda!
Decided to stick with Javascript across
the full-stack.
44. Third Objective Down!
Moisture
Tracking
I need to track the plant
moisture.
1. Get the data
2. Send the data!
Notifications Automated Watering
I need to know if the plant is
dry.
If sensor reading is less than
dryness threshold => ALERT!
Fix the problem!
If dry,
1. Issue Watering Command
2. Water the Plant
Extensibility
Ability to grow, extend and
scale my solution.
No better place than on
AWS for this :)