Software apps and online services
- Description: Control heater remotely, see historical stats
- Difficulty: Medium
- Hardware: ESP8266, MCP9808 sensor
- AWS services: AWS IoT (device shadow API), AWS DynamoDB, AWS S3, AWS Cognito
This is a "Smart Heater," for example the heater device reports current temperature, responds to the status requests and to the heater on/off command.
- Hardware: ESP8266 NodeMCU
- Google and/or Facebook account
- Amazon AWS account
awsmanagement utility (see https://aws.amazon.com/cli)
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)
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.Code with Instructions
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: "email@example.com", 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.Thanks
If you like this and find useful, please hit the 'Respect project' button and don't forget to 'Share'. That way we will hear your feedback and bring even more exciting projects to you door.
Questions? Feedback? Reach us via forum.cesanta.com