Code Monkey home page Code Monkey logo

aws-iot-button's Introduction

AWS IoT button example

This is an Internet Button reference project: when a button on the device is pressed, a cloud backend gets a notification and performs an action. In this particular case, AWS Lambda function sends an email to the specific email address. But, again, the action could be anything.

aws iot button

Prerequisites

Architecture

The data flow is as follows:

  • User presses the button
  • Device sends a message to the MQTT topic DEVICE_ID/button_pressed
  • AWS IoT receives the message and calls AWS Lambda Function
  • AWS Lambda Function publishes a message to the AWS SNS (Simple Notification Service)
  • AWS SNS notifies subscribers: in this case, just sends a message to a single email address
  • User receives the email

Build instructions

  1. Follow the Cloud side setup instructions to setup AWS CLI utility and your AWS credentials
  2. Follow the Device setup instructions to setup your device and provision it to the AWS IoT
  3. Download this repository as a zip file and extract this app on your computer
  4. Exit any running mos.exe process
  5. Open a command prompt (on Windows) or terminal (on Mac/Linux) and go to the extracted app.
  6. You should be able to see the mos.yml file by running dir mos.yml command (on Windows) or ls -l mos.yml (on Mac/Linux)
  7. Find out your device ID
mos config-get device.id

On Windows, here and further, you might need to specify the full path to the mos.exe binary:

c:\path\to\mos.exe config-get device.id
  1. Run the following command to create AWS Cloud Formation stack. Change $DEVICE_ID to your actual device ID, and $MY_EMAIL to your email:
aws cloudformation create-stack --stack-name my-internet-button --parameters ParameterKey=TopicName,ParameterValue=$DEVICE_ID/button_pressed ParameterKey=SubscriptionEmail,ParameterValue=$MY_EMAIL --capabilities CAPABILITY_IAM --template-body file://aws_button_template.json
  1. Wait until the stack creation is completed (it may take a few minutes). Alternatively, you can use the web UI to check the status and read event details: https://console.aws.amazon.com/cloudformation/home

  2. During the stack creation, AWS will send a Subscription Confirmation email, so check your email and confirm the subscription by following a link.

  3. Run the following command to ensure that the stack creation is complete:

aws cloudformation wait stack-create-complete --stack-name my-internet-button
  1. Copy the fs/init.js file to your device:
mos put fs/init.js
  1. Attach to the device to see the device logs
mos console
  1. Reboot your device by pressing a reboot button
  2. When the device is connected to the AWS IoT, push the "flash" button on your device. In the device's console, you'll see a message like this:
Published: yes topic: esp8266_DA84C1/button_pressed message: {"free_ram":26824,"total_ram":44520}

Now, check your email. It'll contain a new message:

Button pressed: esp8266_DA84C1/button_pressed
  1. Now you can go to your AWS dashboard and play with your stack. For example, you may add more subscriptions to the SNS: other than sending emails, it can also call some URL, send SMS, etc. And, of course, you can modify your lambda function to do whatever you want in response to the button press.

aws-iot-button's People

Contributors

cpq avatar dimonomid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.