Arduino and Numerous, with help from IFTTT

Here’s one way to connect an Arduino to a Numerous metric.

The best solution would be to port the Numerous API to the Arduino; however, there is a footprint problem especially with SSL: there is only 2K of RAM on a standard Arduino. I could not find any Arduino ports of SSL (which is required by Numerous).

Maybe Numerous needs to provide a port 80 (non-SSL) interface, though that risks exposing your API key “to the world” in transit. In the meantime, that leaves two alternatives:

  1. Use another computer, local to the Arduino, as a bridge.
  2. Send data directly from the Arduino to Numerous another way.

Option 1 is what I’ve been doing up until now. You write Arduino code to send data out the USB port and write “bridge” code on a small Linux box (e.g., a Raspberry Pi). The Linux code reads the USB data and processes it further (e.g., sends it to NumerousApp). A variation of this can be done with a tiny web server (or other TCP server) on an Arduino instead using USB (I’ve done that too).

With IFTTT integration we can go the option 2 route and eliminate the Linux box, at the cost of giving up some security (more on this later).

You will need:

  • An IFTTT account (free).
  • Connect the Maker channel to your IFTTT account (free).
  • An Ethernet shield (wired or WiFi) on your Arduino.

Go sign up for IFTTT if you haven’t already, and connect the Maker channel.

When you connect the Maker channel you will see a page that looks like this:

mc1

You need the key as shown; this will go into your Arduino code in a moment.

[ No, of course that’s not my real key shown above ]

Next you need to create an event that will be triggered from the Arduino. Go back to your home IFTTT page and create a new recipe, using the Maker channel as the IF part. Give your event a name, in this case I used “arduino_example”

xt1

When you press Create Trigger you’ll be taken to the “THAT” part of the recipe. Find the Numerous channel and select it (you will have to “connect” it if this is your first time), then for this example choose “Update a Number”:

ct

You will next see a screen where you can select one of your Numerous metrics to be updated, and select what value to update it with. You want to use an “ingredient” (click on the beaker/test-tube thing) and you should select one of the Value fields like “value1”. Whatever you select here is what you will code into your Arduino code; as you can see you can return up to three different values to use with one single event.

ing

That’s it … now to write some Arduino code to generate this event.

You need to know the secret key you were given when you connected the Maker channel, the name of the event you created (“arduino_example” in this case), and which of the values you decided to connect to the metric (“Value1” in this case). Then “all” you need to do is generate a simple POST request from your Arduino in the appropriate format.  That format can be found from www.ifttt.com/Maker (you can also recover your key from there). Click on “How to Trigger events” and it will show you the request format you need to generate.

I’ve written some example Arduino code to do this and made it available as a Gist:

https://gist.github.com/outofmbufs/d6ced37b49a484c495f0

As you can see from that code, the format of the URL that you POST to is:

/trigger/{event-name}/with/key/{your-key}

With the server being at “maker.ifttt.com” (port 80 for standard HTTP)

You POST a JSON object that looks like this:

{ "value1" : "123", 
  "value2" : "456", 
  "value3" : "values can be strings too" }

As you can see from the code itself, squeezing this into the primitives available in the Arduino environment isn’t always pretty; you especially need to be very careful about using up too much memory for “programming niceness”. But the code shows you one way to construct the POST, with the minimal set of HTTP headers that will work, and some example values. You can put this into your own Arduino application and modify it as necessary.

A few tricky points worth noting:

  • I don’t know how often you can generate an IFTTT/Maker event without triggering some kind of limit. In this code I limited the updates to once every five minutes.
  • Don’t forget that all-important “L” on your delay() constants if they are “large” (larger then 32000 milliseconds). Arduino is a 16 bit machine and you won’t get the result you want if you say delay(300*1000) with no “L” on the constant.
  • All those string literals use up RAM. You probably already understand this (or will soon) if you are an Arduino programmer. You might want to look up PROGMEM and ways of getting those literals into flash (program) memory instead of RAM.

About security: we’ve bypassed SSL on the path from the Arduino to IFTTT. The path between IFTTT/Maker and our Numerous account is still secure (via SSL) but the POST request that we are transmitting to IFTTT is plain text and potentially viewable “in transit” if you are inclined to worry about such things. This means your IFTTT/Maker key will be visible to anyone who has access to the intermediate routers. If this matters to you, you will need to go back to Option 1 (local bridge/Linux machine and secure connection to the outside world). On the other hand, if all you are doing is exporting the current temperature of your fridge to a Numerous metric, it’s not clear you need to worry so much about this. You should also keep in mind that the IFTTT key doesn’t really let anyone “do” anything other than post bogus events to your trigger. If you are worried that someone would do that to confuse you about your refrigerator temperature, then you need to go back to the “option 1” architecture which uses SSL to communicate to the outside world. But for a lot of applications this will be a handy way to easily connect an Arduino to Numerous (or anything else IFTTT can connect to).

Leave a Reply

Your email address will not be published. Required fields are marked *