1. Follow the setup at https://aws.amazon.com/iot/button to configure your button to connect to Wifi.
2. Activate your Button. If prompted, follow the easy wizard to text your phone with an SMS action when the button is pressed. This will give you a framework for adjusting the button's actions later.
Activate your button by registering it here:
https://aws.amazon.com/iot/button
You will need the following provided information:
DSN: G030JF0553******
Activiation Code: SFI***
Great! Your AWS IoT Button (Beta) is now activated. You have created:
- A Thing called "iotbuttonG030JF0553*****"
- A Certificate for this Thing
- A Policy called "iot-button-policy" which allows your AWS IoT Button (Beta) to send messages
You can access your "Things" at the following link:
https://console.aws.amazon.com/iot
3. Create your IFTTT Maker Channel:
Go here and click Connect: https://ifttt.com/maker
Create an account if necessary.
4. Obtain your IFTTT Maker Channel Key
After setting up the channel, go back to https://ifttt.com/maker and get your key. You may have to click a link to create one. When done you should get a key like the following:
Your key is: c4tmL7kuKr5uptsheL0HEuH4FUm***-1LIPmMwo8***
Part 25. Set up IFTTT Recipes:
After you have your Key, we now need to create 3 recipes. Go here:
https://ifttt.com/myrecipes/personal
Click Create a Recipe, and then click the word "this".
Type in "maker" to find the Maker channel, then click it. Click Receive a Web Request.
The Maker Channel and its "trigger" is really just a conduit through which to receive various actions sent from your button. It's easiest to create a recipe for each type of button press - SINGLE, DOUBLE, and LONG, which can all be tied to different IFTTT actions. Later we will have to pass these as "event names" from AWS Lambda.
For Event Name, type "AWS-SINGLE", then click Create Trigger.
Next click "that".
This is where you will create an action to fire when the AWS button is single-pressed. This is the real magic here - you can pick ANY IFTTT output channel as your action - anything from interacting with an consumer devices such as a WeMo-enabled products or Philips HUE lights, to simply texting your cellphone. In this example, we will send a simple text as an example. The real world implementation will be up to you for each button press type.
If you haven't specified an action of your own, type "SMS" in for Choose Action Channel. Click on SMS. (Note: Do NOT click on Android SMS - it is different.)
Click Send me an SMS.
Replace the message text with the following:
Yay! Your AWS button was SINGLE pressed. This caused the maker channel event called {{EventName}} to trigger, causing your AWS SINGLE Press recipe to fire.
Click Create Action.
Change your recipe title to "AWS SINGLE Press", then click Create Recipe.
Yay, you're done with the first recipe! Repeat Step 5 again, changing SINGLE to DOUBLE where necessary. Finally, create a third recipe replacing SINGLE with LONG where necessary.
By this point you should have 3 recipes which all do something (in our example, send text messages). Now we need to get the button to pass AWS-SINGLE, AWS-DOUBLE, etc events from Lambda to IFTTT when you press your button.
6. Create Lambda -> IFTTT Forwarder function
You will next create a Lambda function to forward events from your button to IFTTT. Create a new Lamdba resource named "AWSIoTButton" and add the following code to it:
AWS.config.update({region:'us-east-1'});
var IFTTTkey = "<YOUR KEY>";
var request = require('request');
//this is called when the AWS Button is pressed and event data is passed as well
exports.handler = function(event, context) {
console.log("Received AWS Button event: " + event.clickType + ". Firing IFTTT Maker Trigger...");
request('https://maker.ifttt.com/trigger/' + 'AWS-'+ buttonState + '/with/key/' + IFTTTkey, function (error, response, body) {
console.log("Complete! Response: ", response.statusCode);
}
)};
7. During your IoT Button Setup, you created an action to use SNS to text your phone when the button is pressed. Inside the IoT Dashboard, find the item named <your thing name>Rule. Click the name, and in the right pane, add a new Lambda action. Select the AWSIoTButton function we created. You can leave the first SNS function or remove it if you choose.
That's it! Enjoy creating new and interesting recipes for your button, the possibilities are limitless!
Comments