Fridges and coffee machines are probably in the top 3 “things an IoT tinkerer is likely to connect one day or another…”. Not wanting to fail tradition, the tech team at EVRYTHNG decided it was time to connect our dear coffee machine to the Web through the EVRYTHNG API.
“Connected as in I can send a tweet to your coffee machine and it makes me coffee?”, I hear you say. Not at all! That is so last year. 😉 We, at EVRYTHNG, are used to connecting dumb (as in no-electronics-beyond-tags) products and giving them a digital identity. Thus, our coffee machine is activated by checking-in and scanning (NFC, QR or IR) packs of coffee.
As such, this recipe is about wiring an mbed device to the electronics of an off-the-shelve coffee machine, then connecting the mbed to the EVRYTHNG API and creating a mobile web page that communicates with the machine through the EVRYTHNG API.
As usual, all the ingredients you need can be found in the EVRYTHNG’s eBay Collections then simply follow the steps below and you should be good to go!
Part 1: The Hardware
The first step is probably the one that is going to get your hands really dirty (with solder!). When starting the project, I looked for a decent coffee machine that would also offer an API because after all, it’s 2014! The only model I could find (shout in the comments below if you know of any other), is a Jura Ethernet machine. However, I think the model has been discontinued. Thus, we had no other choice but to buy a good off-the-shelve machine and hack into it.
The machine we picked is a Delongi but most of the guidelines here should work with any machine. The easiest way of hacking it was to find the button panel and solder cables directly at the back of the buttons, as shown below. To make it more fun we connected one cable to the ‘Coffee’ button, one to the ‘Espresso’ button.
The cables are then connected to the embedded device: an mbed NXP LPC1768 in our case but most mbeds will do (or any other embedded device if you don’t want to reuse the code!). The mbed is then connected to a prototyping board with two relays. The whole thing is pretty straightforward: the relays are connected to two of the mbed’s GPIO ports, allowing us to programatically give the necessary impulse to emulate a button press on the coffee machine.
Part 2: The Cloud
Next comes the Web of Things part. In this case, rather than running a Webserver directly on the device and offering a direct REST API we’ll use a proxy. In Web of Things terminology this is called using a smart gateway. The motto of the EVRYTHNG API is to give every object an API, so let’s simply use it as the API the final Web app will trigger to get a coffee served.
The EVRYTHNG API offers a simple and straightforward way to give a REST API to things that don’t have a Webserver. Instances of physical objects are represented as ‘Thngs’ in the EVRYTHNG world. So, start by creating a ‘Thng’ to represent your coffee machine.
The dynamic data of ‘Thngs’ is represented by ‘Properties’. Creating a ‘Thng’ with properties is quite straightforward, here is what it would look like with jQuery (click on the ‘edit’ link to add your EVRYTHNG API key and run this code directly!):
Note that because the EVRYTHNG API supports both CORS and JSONp this request will work directly in any sufficiently recent browser.
Part 3: The Trigger
Here, most IoT hacks out there would tell you “and then you tweet and get a coffee served”, but since we are using the EVRYTHNG API how about “whenever you scan a pack of coffee you get the machine to give you a free coffee straight ahead?”. Okay? Well let’s implement that then!
The portal also directly creates a QR corresponding to the redirection so you can directly put it on the pack. If you’d like, just like us, to write it onto an NFC tag as well just take the short URL (e.g., http://tn.gg/1AQ9srw1wy) and burn it on the tag. To do this, I would suggest using the nice NXP TagWriter app which lets you copy the content of a QR code onto an NFC tag.
Next step is to write the Web page that will actually trigger the Coffee Machine through the EVRYTHNG API. Let’s use jQuery again:
Part 4: the Embedded Software
Finally we need to upload some code to the embedded device in order for it to read the Coffee Machine’s ‘cmd’ Property on a regular basis and check if a coffee was ordered (Yes, I know, I know, we should have used a push mechanism instead of polling just like that but we wanted to keep the project lean and simple!)
Obviously the code you’ll have to write will depend on the specific embedded device you want to use. But basically all the code does it:
- Check on a regular basis if the ‘cmd’ Property contains ‘espresso’ or ‘coffee’
- If it does then activate the corresponding GPIO
- Update the ‘cmd’ Property to ‘done’ to signal the fact the coffee was served!
Here is what it would look like for an mbed device, please note that you’ll need to import the EVRYTHNG mbed Wrapper (search for ‘EVRYTHNG’ with the import wizard):
Now: what will happen is that scanning the QR or NFC tag on the pack of coffee will trigger our Web app with the right Product Id, this Web app will update the corresponding property with either Espresso or Coffee. The mbed will monitor the same Property on the EVRYTHNG API and as soon it detects a changes it will push some current on the GPIO port, triggering the Espresso or Coffee button!
Check back in a couple of weeks for the next in the recipe blog series: Smart Fussball Table, in the meantime, go and check out the rest of EVRTHNGâ€™s eBay Collections.