Original URL: https://www.theregister.com/2013/11/25/review_electric_imp_internet_of_things_card/

Little devil: Electric Imp is an Internet of Things Wi-Fi PC-ON-AN-SD-CARD

The card micro that makes connecting projects to the cloud easy

By Tony Smith

Posted in Software, 25th November 2013 09:31 GMT

Review Most products’ origins are prosaic: an inventor or a suit spots a gap in the market and attempts to fill it. Other products, however, have rather more bizarre beginnings. A case in point: Electric Imp came about because co-founder Hugo Fiennes wanted to connect the lights in his new bathroom to the internet.

That’s just the kind of slightly bonkers project that members of the world’s maker community like to tackle. With the world’s first in-car MP3 player, the Empeg, to his credit, not to mention his role coaching the team behind the first four iPhones, Fiennes figured he had the savvy to link his lights to online data sources in order to, say, change the colour to match the weather forecast or Google’s share price.

Electric Imp and Impee

Electric Imp’s Imp: enabling the Internet of Things in an SD card case

But it proved a more complex job than it needed to be. Directly coupling off-the-shelf networking hardware to your electronics isn’t easy, yet it's necessary if you’re to base a project around something more power efficient than a tiny computer running a full OS needed to control a USB or PCIe Wi-Fi adaptor.

Fiennes’ thinking brought him to the notion of a very small wireless device that could be readily integrated into a project to allow the maker to focus on the electronics and not to have to worry about connectivity, protocols, web and app integration, and all that malarkey.

Conveniently for someone of an entrepreneurial bent, the doohickey might also appeal to commercial product developers looking for an easy way to bring new or existing kit into the Internet of Things. Makers and manufacturers, Fiennes’ concept could serve them all.

Fiennes formed Electric Imp to create the gadget, today called the Imp; its lightweight operating system, ImpOS; and the server technology - Imp Cloud, would you believe? - that would allow hardware to operate smoothly over the internet. Founded in 2011, the company kept its head below the parapet until 2012, and it’s been a visible if small startup since then.

Electric Imp and Impee

ARM inside

The Imp itself is an SD-like card that contains a 32-bit ARM Cortex-M3 processor core, 160KB of memory - the firmware takes up about 80KB of that, leaving the rest for program code - and a 2.4GHz 802.11n Wi-Fi transceiver. Electric Imp reckons the CPU is good for all but the most demanding of computational tasks. (Fiennes should know: he wrote communications software for ARM-powered Acorn computers in the 1990s, and his company The Serial Port produced various hardware add-ons for the machines.)

There’s not much the way of a GPU, of course, but there is a status LED. There is also an optical sensor to pick up configuration data flashed up on a phone’s display, a process Electric Imp calls “blinking up” the device.

I say the Imp is “SD-like”: looking at it, you’d never think it wasn’t an SD card. It’s not - Electric Imp is simply taking advantage of the off-the-shelf card design and associated slot mechanisms to ease the implementation of Imp in third-party products. So don’t try and stick it in your camera, OK? That said, the Imp’s connectors are electrically compatible with a real SD card, so it won’t do any harm.

The Imp itself is, like a newborn, largely useless on its own. It needs a source of sustenance and a mechanism for communicating with the outside world. Commercial users will slip an Imp into a slot inside their product; makers will want an “Impee”, which is the generic name for small breakout boards able to take an Imp, feed it with power and convert the SD format’s connectors to a set of GPIO pins.

Electric Imp and Impee

You can power the Imp by Mini USB or battery

Electric Imp’s own, developer-centric Impee, dubbed ‘April’, sports a spring-loaded SD slot necessarily trimmed back so the metal doesn’t interfere with the card’s Wi-Fi signal. The antenna is located at the end of the card away from the connector pins. The Impee features a mini USB port for power – not data, though - but it also has positive and negative terminals for hooking up a battery. A jumper on card lets you specify which of these two power sources to use.

Finally, there are 11 holes into which you can solder pins to allow the board to be hooked up to ribbon cables or, in my case, fitted onto a bog-standard solderless breadboard.

Incidentally, Electric Imp also offers a version created to be soldered into a product. More details here (PDF).

The Impee’s not yet ready to be hooked up to electronics projects yet – the powered Imp needs to “blink up” first. For this you’ll need Electric Imp’s mobile app, which allows you to prime the Imp for the wireless network it’ll be connecting to. It’s available on Android and iOS; it was recently updated for iOS 7.

Blink me

The phone’s favoured wireless network is already listed for the Imp to use, but you can enter others, along with their passwords. I had to do this: my main WLAN, presented by the app, sits in the 5GHz band, a region the Imp’s 2.4GHz radio can’t access. The Imp currently remembers only one wireless network, but Electric Imp developer relations chief, Matt Haines, tells me upcoming ImpOS upgrades may allow multiple networks to be recorded and add the ability to hop onto free hotspots out in the wild.

Whether you use the network the phone already knows about or key in the details of another one, you next hold the phone’s screen up against a tiny window on the end of the Imp, and the SSID and associated WPA key are literally flashed across. Audio tones tell you when to put screen to card and take it away again. If all’s well, the card will now connect to the internet and Electric Imp’s servers, download and apply any firmware updates.

Now it’s ready to use.

Electric Imp app

Electric Imp’s app: choose or enter your WLAN’s details (left) then prepare to flash the data to the Imp (right)

Programming the Imp is carried out in an online IDE. Imp uses an object-oriented scripting language called Squirrel to code two event-driven programs that run in parallel: one in the Imp, the other on Electric Imp’s servers. The latter program is called an “Agent” and it provides a web-based (HTTPS) mechanism for routing control commands and data over the internet to your Imp. Electric Imp manages the security and handles accessing Imps across routers’ NAT tables and firewalls, but of course you’ll need to sign up for a free account to make use of it.

Each Agent is assigned a unique web address which can then be embedded in a local HTML page presented by a browser or coded into a mobile app and accessed using Android and iOS stock URL handlers. You can pass named parameters tacked onto the end of the URL just as you would if you were scripting basic browser-server interaction, and code the Agent to parse those parameters when it’s passed an inbound request.

One response the Agent can make is to fire off a message to the device. The second program, running on the Imp, in turn reacts to this message by calling functions that can examine data sent by the Agent and perform actions accordingly, typically by sending signals out through the GPIO ports, the three-channel UART, two-channel I2C and two-channel SPI buses, either to control another device or to read data from it.

The Imp code can then send a message back to the Agent, to which it can respond, perhaps by informing the browser or app in front of the user, or to send further messages back to the device. You might, for instance, want to perform particularly weighty calculations on the back end to help keep the device’s power consumption as low as possible. But the Imp has processing resources to apply logic to the data coming in off through the GPIO.

Electric Imp IDE

You code a Model’s Agents and Imps in an online IDE
Click for larger image

It’s not hard to imagine a typical usage scenario. A mobile app asks for, receives and displays the temperature in your living room, from the Imp, then allows you to turn the central heating on if it’s getting a bit nippy. A more advanced version might detect that you’ve left work for home, that it’s the middle of winter and so interrogate an online weather service to see if it had better get the boiler fired up on your behalf.

The big question, of course, is whether the intelligence to handle this goes in the device - via the Imp, say - or resides in the app. By giving the Imp compute capability, it can also run code that doesn’t need user interaction.

Electric Imp’s IDE presents Agent code side by side with the Device code so it’s easy to look back and forth between them to ensure, say, you’ve got your message parameters applied consistently. You can have the IDE error-check the code without beaming it to the Imp, or upload and run Agent code and device code immediately.

Together Agent code and device code form what Electric Imp calls a “Model”. Only one Model can be applied to an Imp at once, and Electric Imp could improve how you work on multiple Models in parallel. As it stands, a Model that’s not currently associated with an Imp can’t be edited. Multiple Imps can be assigned the same Model.

Electric Imp

Breadboarded, powered and connected

The IDE doesn’t compile code: ImpOS incorporates a Squirrel interpreter. There’s clearly a small memory penalty involved in storing tokenised source code on the device rather than machine code, admits Haines, but the quid pro quo is that it makes it almost impossible to crash the hardware: the interpreter should be able to catch and stop any code before it takes out the system. On a lightweight embedded device in particular, compiled bare-metal code may find it has the freedom to cause more havoc.

The Squirrel language itself is not too hard to get to grips with if you’ve programmed C or Python before, and you’re doing relatively simple stuff. More complex code has a steeper learning curve. Being interpreted, it has one or two weak spots, bit-level maths operations in particular. The language has been used in a number of video games as a scripting language, but its use isn’t widespread. The available documentation is aimed more at the computer scientist than at the amateur programmer.

Squirrel is available under the open source MIT licence, but at this stage only its creator, Alberto Demichelis, is working on its future development and expansion.

Internet enabling... anything

The Imp API is a work in progress too, but it’s already capable. It defines object representations of the Imp itself and its key features, including pins, buses, timers, non-volatile storage, its wireless sub-system, its sleep mechanism and such to allow code running on the device to access these features. It also maintains separate representations of the Imp and the Agent to allow each to register on one the code that will be run when a message comes in from the other, and to respond if necessary.

Electric Imp and Impee

Eleven pins for power and GPIO

Agent software can also make use of an HTTP-centric API to mediate communications between a browser or a mobile app and the Agent, and to prepare and interpret data transmitted in JSON form. Data can be encrypted for security. The Agent can also interact with the server it’s running on.

Electric Imp’s own tutorial code was sufficient to allow me to begin adapting it to switch a red LED lamp on my breadboard on and off remotely and then to add a second, green LED using a second GPIO pin as a switch. A third, amber LED and you have a set of traffic lights YOU can control. Kind of.

Whatever, there’s a real buzz to be had when you so easily and so quickly get something usually so complicated to work. With the basics of browser-Agent-Imp communication established, it wasn’t hard to subsequently hook up the small thermal printer I usually run off my Raspberry Pi’s UART bus to the breadboard and have the Imp print different messages depending on the value of a parameter passed to the Agent’s unique URL.

All I had to do was enable UART communications on the Imp. The printer’s documentation provided the local control command characters, and equally a way for the Imp to check on the status of the printer so it can tell me if the paper has run out, there are problems with the power, or it has overheated, say.

Electric Imp

App to internet: “Print.” Internet to Imp: “Print.” Imp to printer: “Print.” Printer prints

Half an hour later, I had a working iPhone app able to trigger printed messages remotely at the touch of a button. These are trivial applications intended only for testing, of course, but they show that the Imp has a lot of potential.

It’s entirely possible to do this with the Raspberry Pi, the Beaglebone and the various Arduino boards. Indeed, Imp’s size is less of a USP now that you can get very small DIY microcontroller units, such as Adafruit’s Arduino-friendly Trinket, which are more robust than the Imp alone. There’s a cost-saving logic to putting the Imp inside an SD card casing, but since you’ll need some kind of connector to interface it to the rest of your hardware - even if you’re not using an Impee - it’s not actually as practical a form-factor as you might think.

But what Electric Imp provides out of the box and which these alternatives don’t is a clear, functional API for responding to incoming control and information request messages. It also has cloud infrastructure in place so you don’t need to set all that up either. Haines says it's good to support hundreds of thousands of Imps and work is under way to scale it to cope with millions of the devices.

Of course, all this development work is predicated on this small startup persuading big customers to put its technology into their existing and new products to allow that kit to communicate over the internet. Some, such as GE, are already starting to do so, but there’s a long way to go.

Quirky.com Spotter

Quirky.com’s Spotter is a product based on Electric Imp tech

The Reg Verdict

The Imp is a great way to connect projects and products to the internet. The hardware is inexpensive - $30/£24 for the Imp; $13/£16 for an Impee breakout board - and if the Squirrel language used to program it is unfamiliar, it’s not at all hard to pick up. The Imp API is clear and capable. It really makes Wi-Fi easy, and its power-saving modes can apparently eke out battery life for months.

All this confirms the Imp as a powerful alternative to more established DIY computing platforms if your project needs internet connectivity for remote control or sensing. Don’t take my word for it: the Imp’s asking price is low enough to try if for yourself.

When you’re remote-controlling your hardware after a just a half-hour’s experimentation, you’ll wonder why you hadn’t embraced the Imp and the Internet of Things before. ®