We demonstrate an easy setup that allows anyone to send commands to your Internet of Things (IoT) device and get feedback. Our device of choice is Particle’s Internet Button (11 LEDs & 4 buttons) and we use an Android phone as SMS gateway. IFTTT‘s simple if-this-then-that recipes connect the Internet Button and the gateway phone.
The following illustration shows the steps in a complete command/confirmation loop.
- Someone sends a text message with a command (e.g. LED 1 on/off) to your phone
- Your phone receives the message and triggers an IFTTT recipe
- IFTTT passes the message on to the Internet Button by calling a function
- The Internet Button interprets the message, executes the command and publishes a confirmation event
- The confirmation event triggers another IFTTT recipe that sends an SMS from your phone
- The original sender receives the command confirmation and is happy
The following sections explain how to make that happen.
Get your Internet Button ready
Particle’s Internet Button is a Wi-Fi enabled IoT device that features 4 buttons, 11 RGB LEDs, a speaker as well as an accelerometer and is programmed over the air.
Your Internet Button needs to be able to do two things:
- Expose an API that can be called from IFTTT
- Publish events that trigger IFTTT recipes
Particle’s so-called Cloud Functions make this a breeze and the following code shows how:
That’s all there’s to it, just run the above code on your Internet Button and it’s ready. (Please refer to Particle’s documentation for getting started with the Internet Button. It’s straightforward and it shouldn’t take long until you can run your code.)
Now, let’s create the IFTTT recipes to connect your Internet Button to your phone.
Create the if-this-then-that (IFTTT) recipes
IFTTT is a platform which lets you create simple rules (so-called recipes) connecting two services/devices without the need to write any code.
To create the three necessary recipes, you need:
- An IFTTT account
- The Android SMS Channel connected to your account
- The Particle Channel connected to your account
The first recipe passes the command from the SMS gateway, i.e. your phone, to your Internet Button:
The input will then be split and parsed as shown in the Internet Button code above.
The second recipe sends a confirmation SMS upon an event published by the Internet Button:
{{EventContents}}
contains the original sender’s number as can be seen in the Internet Button code above.
The third recipe is a mere courtesy in case the Internet Button doesn’t understand the command:
That’s all. Now, your friends can talk to your Internet Button.
This is just one of a myriad of use cases you can achieve with these techniques – the possibilities for prototyping and real world applications are almost endless.
Interested?
Drop us a line if you’re interested in a hands-on experience. We’ll organize a workshop in the near future.