eBay’s IoT Collections: The NFC-Automated Home

In our penultimate eBay Internet of Things Collections blog post we wanted to talk about a cheap way of making your house a little smarter, one NFC or QR tag at a time!

A little while ago we were showing you how you could use NFC and the Trigger app to create a ‘cheap smart home’. The app basically lets you create actions that are triggered whenever an NFC tag is seen close to your phone (as in ‘touching your phone’ kind of close).

Don’t get me wrong, the app is awesome and I use it on a regular basis (my home is all NFC-enabled!) but it has two drawbacks: a) it requires NFC and not everyone out there has an NFC phone (ahem… e.g. all iPhone users…) and, b) it requires an app, which means that people wanting to interact with your shiny NFC enabled doorbell will have to download an app first, not exactly the kind of thing you would want. 🙂

However, there is hope and it’s called a URL. In the Web of Things, all devices are accessible via URLs. So all you need to do in order to get data from a device is to use its URL.

As an example, the accessing of the following URL ‘https://api.evrythng.com/thngs/5357ac4be4b0eec2cc69487c/cmd?access_token=…’ allows me to see the time and type of coffee the Connected Coffee Machine we built earlier last served.

All we need to do now to create a trigger for this is to write this URL in an NFC tag or encode it in a QR code. And off you go, no app/coding required!

Well in theory because there are two problems with this: first, these URLs are too long to be encoded in cheap NFC tags or easily readable QRs, and secondly, this works only to read data from a connected thing – not to control it as controlling it requires invoking the URL with a payload, which isn’t part of the URL but of the… HTTP body.

However all hope is not lost, here is how we can use the free EVRYTHNG API to solve the two problems in a matter of minutes. Firstly, log onto the EVRYTHNG developer dashboard and access the profile of our Connected Coffee Machine (see here for how to create that). Now, create a redirection for this thing to the URL https://api.evrythng.com/thngs/{thngId}/cmd?access_token=… (notice the {thngId} which will be automatically replaced by the actual Thng ID whenever triggered). By doing this you also get the corresponding QR code containing a redirection to the URL (what we call a short URL, e.g., http://tn.gg/9FhzpUChuB in my case) which means it is easily readable by a QR reader and fits in any NFC tag.

So, with this first problem solved how do we solve the HTTP body problem?

Well the EVRYTHNG API offers a proxy that let’s you encapsulate a full HTTP request in a URL. While this is evil from many points of view (e.g., it isn’t RESTful!) it does the job for our use-case. The proxy we offer is called a JSONp proxy and you can find its documentation here. Basically we put the whole request in the URL: the body, here:

[[{"cmd" : "espresso"}]], 

the HTTP method here, PUT and finally our API key (beware, this means anyone able to see the URL will be able to see the key and hence control your Thngs!).

https://js-api.evrythng.com/thngs/5357ac4be40eec2cc69487c/properties/cmd?access_token=your_token_here&data=%5B%7B"cmd"%20%2A%20"espresso"%7D%5D&method=put&callback=abc

Note that you’ll need to URL encode the data first with a tool like Meyer Web Encoder

All we need to do then is to save this URL as the redirection for our Coffee Machine (i.e. our Thng) as you can see on the screenshot below.

Selection_139

Now, just by scanning the QR code you will automagically get an espresso! You could reproduce the exact same idea for literally any device that offers a Web API, e.g. a Sonos music system or Logitech UE Smart Radio, a Hue Lamp (LINK), anything connected to a heimcontrol.js enabled Raspberry PI, your Spark.io enabled doorbell, Connected Smart TV or OpenPicus Flyport enabled Xmas Tree

Okay, okay, but how about putting this in NFC tags? Well considering an NFC tag from a identifier view-point only, it’s like a QR code, only easier to interact with. Back in the days we spent time evaluating this and it turned out people liked interacting with NFC tags much more than with QR codes (for some reason most people seem to prefer touching over looking and say it is more natural (I wondering why… ;-)). So yes, let’s put that in an NFC tag!

This is pretty straightforward as NFC tags can encode URLs. The easiest way to get this working is to use a nice NFC app called NFC Tag Writer The app basically lets you copy the QR code to an NFC tag: scan the QR code for the redirection on the EVRYTHNG developer portal and simply copy it’s content (the short URL) onto the NFC tag.

And there you go, you have implemented a cheap home automation system without the need to craft any line of code!

 

Leave a Reply

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