The Onion + IFTTT Experience

IFTTT

In this tutorial/mini-project, we will show you how to do some very cool things using IFTTT, the Omega and the Onion Cloud. Specifically, we will use the IFTTT DO App on a SmartPhone to send the date and GPS information from your phone to be printed remotely on your Omega’s OLED Expansion. This tutorial will give you a taste of the Onion Cloud and its capabilities. Let’s get into it.

Imgur

[[TOC]]

Overview

Tutorial Difficulty:

Beginner

Time Required:

20 minutes

Required Materials:

Useful Experience:

Background Info

What is IFTTT

IFTTT stands for “if this, then that”, which is a web service that allows users to create custom tasks, which are called “recipes”, that can set up user’s own conditional statement (e.g. if I receive a new email on my gmail account, then forward it to another account). The conditional statement could be as simple as if a button is pressed, or as complex as you want. There is also “DO button” app in APPstore or Google Play store,which allows the recipe to be triggered by pressing a button on the app. We will be using te “DO” app in our tutorial. In the next section, I will explain what will be going on behind the scenes.

IFTTT

Theory & Introduction

The theory of using IFTTT to control our Omega is, when one event is triggered, a request is sent to the Onion Cloud via the Maker Channel. The Onion Cloud will then send a command to your local Omega to execute a ubus function. We have built in Ubus functions to control the Omega’s expansion which is what we are using in this tutorial. If you would like to learn more about ubus or would like to create your own function, check out our ubus tutorial series!

Imgur

The recipes are created through “channels”, which are different web services, for example, Gmail. We are in the process of creating an Onion channel, but in the meantime, we can still use IFTTT through the DIY “Maker” Channel.

Step 1: Setting Up The Omega With The Cloud

Create Onion Account and Register a Device

If you haven’t already, you will need to create an Onion Account on the Onion Website. If you are completely new to the Onion Cloud, click the info button button on the bottom left to take a tour of the Cloud. Use the Device Manager to register your Omega with the Cloud. Again, use the tour button if you’re unsure how anything works!

Imgur

Now that you have a Cloud connected Omega, make a note of it’s Device ID since we will be using it later. Next we will need to get an API Key.

Get Your API Key

API Keys are authentication credentials that are tied to your account and allow other programs to use the Onion Cloud APIs. Click on the Key Manager App on the Cloud to create a API Key to use with IFTTT. Make note of the Key since we will be using it later.

Imgur

Step 2: Setting Up IFTTT

Make An Account With IFTTT.

Go to the IFTTT site and make an account. In the next step we will be making the recipe.

Download DO Button App and Setup Up the “Recipe”

Download and open the DO Button App by IFTTT on your phone. Navigate to the My Recipes section and click the add button. I have included a series of screen shots to guide you through the steps on your phone. Once you have selected the Maker Channel, you will be prompted to connect to the maker channel. Once you have reached the final screen, choose a title for the recipe. I have made mine “omega test”. For the URL field, just put google.com for now and choose the POST for the Method. For “Content type” select “applications/JSON”, scroll to the bottom and click add. We will now continue to modify the recipe on the desktop.

Imgur

Step 3: Creating an IFTTT Recipe.

In this step you will need to log back into the IFTTT website and open up the Onion Cloud. In this step you will modify the URL you entered in step 2 with one that is generated by the onion cloud and that points to your device and tells it to do something. Click on My Recipes, click on DO tab and then on the recipe you created on your phone and you will be able to modify the recipe.

Imgur

Get URL and Body Info From the Onion Cloud

Login into the Onion Cloud, then click on the Device Explorer App on the dashboard: Imgur

Your Device should have a Device ID and be connected to the cloud: Imgur

Click on the device and then the following tabs on the left i2c_exp and then oled-exp. You should reach the following screen: Imgur

Side Note:

We have just selected the ubus command to control the Oled Display via the Onion Cloud. You can select another tab to issue a different command to the Omega. Using the steps below as a baseline, you can easily control any of the expansions or other Omega functionality using steps similar to those below.

Back to the tutorial:

In the command field enter:

set

In the option field enter:

i

In the params field enter:

{"write":""}

Take a look at the i2c-exp-driver Read Me for details on controling the Servo, Relay, and OLED Expansions using ubus commands.

The section under the curl command is what you will use to fill in the URL and body fields in the IFTTT recipe. The link at the end will be the URL to the Onion API and the JSON text before it is the body.

The URL will have the following form:

https://api.onion.io/v1/devices/<device-id>/i2c_exp/oled-exp?key=<API-key>

You will need to replace and with your device ID and API key which you took note of earlier. Enter this into the URL Field.

Next, simply copy the JSON text inside the single quotes as is into the body field. Now let’s add some ingredients, ie date and GPS coordinates. To do this place the cursor in between the empty quotation marks following

"write":

And click on the button beside the field. Select “OccuredAt” from the dropdown menu and click “Add Ingredient”. Repeat the process selecting latitude and longtitude. You will also need to add a space between the last two curly closed brackets. Once you are done, your screen should look something like this and you can hit Update. Imgur Imgur

Step 4: Try It Out!

First make sure the GPS on your on phone is turned on. Open up the DO app, press the button and watch the OLED Display.

Imgur

Using the Project

Using this project, you can use the Onion Cloud to control your remote Omega very easily. Using IFTTT, you can trigger commands either automatically or from your smartphone via the DO button App.

The Onion Cloud can send commands to any connected Omega to execute ubus functions. Therefore, this tutorial can be used as a framework to do other things remotely on your Omega; maybe control a door lock or light switch from your phone, or automatically start an action when you enter a specific area of your city. The world is your playground with the Omega and IFTTT.