AWS IoT Smart Heater
This is a "Smart Heater" example: the heater device reports current temperature, responds to the status requests and to the heater on/off command.
- Hardware: ESP8266 NodeMCU
- Amazon AWS account
awsmanagement tool (see https://aws.amazon.com/cli)
mosmanagement tool installed (see mos installation guide)
The data flow is as follows:
- A device uses I2C temperature sensor and sends data to the AWS IoT periodically
- An AWS IoT rule intercepts temperature data and stores it into the DynamoDB table
- A device gets synchronised with its AWS IoT shadow
- A frontend with OAuth is running on AWS S3, talking to the device shadow to either get the device state, or set the device state (turn it on/off)
Build instructions (Mac/Linux)
First of all, you'll need to create Google and/or Facebook OAuth2 Client, so that users will be able to login into the heater application.
For Facebook: visit Facebook Apps, click "Add a New App", enter some name, like, "My Heater", pick a category, click "Create App ID". When the app creation is done, you'll see the app dashboard. Don't close the tab for now: when your stack is instantiated, you'll need to get back here and enter the Website URL.
You'll see latest graph of the temperature reported from the device, current heater status (on/off), and the switch. Switching the heater is possible only for authenticated and authorized users; click "Sign in with Google".
NOTE: if it complains about mismatched redirect URI, just wait a couple of minutes: the settings in Google Console might need some time to take effect.
If you try to switch the heater status, you'll get the message saying that you are not authorized to do that. Now, you need to authorize your user to manage heater.
For that, navigate to the AWS Cognito console, click "Manage Federated Identities", select "identity_pool_for_DEVICE_ID", click "Edit identity pool", expand "Authentication providers", click on the "Google+" tab, and in the section "Authenticated role selection" change "Use default role" to "Choose role with rules". Here, you can use whatever rule you want. For example, in order to authorize some particular user, you can specify Claim: "email", match type: "Equals", value: "firstname.lastname@example.org", and pick a role "my-heater- myHeaterAdminRole-XXXXXXXX".
After that, you can sign out from your heater app, sign in back, and switching the heater should result in the state being changed.
How to install this app
- Install and start mos tool
- Switch to the Project page, find and import this app, build and flash it: