I wanted to play with the AWS IoT Button and racked my brain to think of how to use it. In our house whoever gets home first checks the mail and then texts the other person to let them know. Believe it or not texting two words “checked mail” every day can get tedious. Even using “Ok google, send message to…” gets tiresome. So I’ve configured my button so a SINGLE click texts my phone with the message “Cathy checked the mail.” A DOUBLE click texts my wife’s phone with “Kyle checked the mail.” And a LONG click texts my phone with the button’s remaining battery voltage.
You will need a laptop or computer with WiFi in order to connect with and configure your IoT Button. This comes in handy later when you find yourself copying/pasting information. This step assumes that you have already created and logged in to your AWS account.
- Go to https://aws.amazon.com/iot/button/
- Click on [Go to Configuration Wizard].
- Select "IoT Button" from the IoT Type drop-down menu.
- Enter your device serial number found on the back of Button.
- Follow the steps in the Wizard to connect to your Button and configure it to connect to WiFi and register it with AWS IoT.
- Continue the steps to create the Lambda function using the provided sample code. We will update that in the Step 3 but for now update the sample code using your email address.
- At this point click your button and it will email you the test message. The sample Lambda function will create the SNS topic that you will configure in Step 2.
The sample Lambda function creates an SNS topic named ‘aws-iot-button-sns-topic’ the first time it is executed. In this step we will add our cellular numbers to that topic to allow sending SMS messages.
- Go to the Amazon SNS Console.
- Click on Topics from the left hand menu.
- Locate the ‘aws-iot-button-sns-topic’ Topic and click on its ARN.
- Click on [Create Subscription].
- Select ‘SMS’ for Protocol.
- For Endpoint enter your cellular number in the 1-138-867-5309 format.
- Click on [Create Subscription].
- Repeat substeps 4-7 for an additional cellular number.
After the sample code has created the SNS Topic updated in Step 2 it has served its purpose. We will store the target phone numbers and messages in Lambda environment variables and then overwrite the sample code with the code in index.js.
/**
* The following JSON template shows what is sent as the payload:
{
"serialNumber": "GXXXXXXXXXXXXXXXXX",
"batteryVoltage": "xxmV",
"clickType": "SINGLE" | "DOUBLE" | "LONG"
}
*
* A "LONG" clickType is sent if the first press lasts longer than 1.5 seconds.
* "SINGLE" and "DOUBLE" clickType payloads are sent for short clicks.
*
* For more documentation, follow the link below.
* http://docs.aws.amazon.com/iot/latest/developerguide/iot-lambda-rule.html
*/
- Go to the Amazon Lambda Console.
- Copy and paste the contents of index.js into your Lambda function.
- Assign an environment variable with the Key of Number1 and Value of +11388675309 (Substitute your actual number.)
- Assign an environment variable with the Key of Message1 and the Value of Alice checked the mail. (Substitute your actual name.)
- Repeat substeps 3-4 for the second target cellular number using the Keys of Number2 and Message2.
- Click on [Save] and click your Button again to test.
- https://aws.amazon.com/iot/button/ (The wizard is refreshingly thorough.)
- https://www.socialcustomer.com/2016/05/how-to-set-up-an-aws-iot-button.html (Some configuration differences but great screenshots, something I've left out of this walkthrough.)