Macadamian Blog

The Internet of Things: Cordova Plugin for Electric Imp’s BlinkUp

Ayesha Khan, Dan Lanthier & Stuart Douglas

The Internet of Things (IoT) is a new and exciting trend where everyday objects are being connected to the internet.

Blinkup Cordova plugin Electric Imp

The Internet of Things (IoT) is a new and exciting trend where everyday objects are being connected to the internet. From consumer applications, to enterprise machine-to-machine communications to healthcare IT, almost every market is showing increasing support for connected devices. And, leading the way in providing connected device solutions across these various markets is Electric Imp.

The Electric Imp Solution

Electric Imp provides an easy-to-use environment to develop custom firmware for their Wi-Fi enabled, SD card-sized micro-controllers that can be integrated with existing circuits and devices. The Electric Imp solution is used in a large range of projects from small do-it-yourself activities to prototypes to mass-produced connected products. Electric Imp also offers a platform to develop and test your code and a lightweight cloud solution called “Agents” that allow the device to communicate with the larger Internet.

One problem remains. The Electric Imp device must be connected to the Internet and be provided with Wi-Fi credentials. Electric Imp determined that this should not be done through the device itself, but through a mobile device. This process is called BlinkUp, and communicates Wi-Fi credentials by flashing light patterns from an iOS or Android phone to a sensor on the Electric Imp device.

Mobile Companion Applications for Internet of Things

In addition to an Internet-enabled device (such as the Imp), an IoT solution generally requires a companion application that allows interaction with the connected device from the Internet. This companion application is typically a mobile app due to the accessibility of mobile devices and their ability to access IoT-enabled devices regardless of location.

While we recommend writing mobile IoT applications in native technologies (e.g. Cocoa on iOS and Java on Android), consider using mobile Web technologies such as Cordova for a minimum viable product. This solution provides some benefits. Code can be easily shared between platforms and Web-savvy developers can be used to create applications. One of the drawbacks of this approach is that native code might need to be invoked from the applications (e.g. accessing phone’s camera or a process that requires high performance). The BlinkUp process requires precise timing and falls into this category. So, how do you solve this problem?

The Cordova Plugin for BlinkUp

Our team developed a Cordova Plugin to bridge the Web technologies of Cordova with the powerful abilities of native apps. Plugins are components written for Cordova in native code and allow access to all of the rich API’s that each platform offers. The most critical aspect in developing a plugin is to define a clear API that works on all supported platforms. The API defines the native functions that JavaScript can invoke as well as the JSON models which the plugin returns to the JavaScript layer. JavaScript does not distinguish between platforms when receiving JSON models which mean that both platforms must ensure that they send back the same models for the same scenarios – even when they may be executed in different ways.

BlinkUp plugin application

We decided to investigate how well the BlinkUp process works within a Cordova-based sample application and experimented with the Cordova Plugin to allow mobile web applications to perform BlinkUp with Electric Imp devices. Apart from defining our APIs, one of the challenges that arose when developing the Cordova Plugin was that the BlinkUp SDK implementations differed between iOS and Android. We needed to ensure the behavior was consistent between both operating systems.

Another challenge when picking a Web-based application was having a design that was consistent on both platforms. For this sample application we intentionally went with a design language similar to iOS that did not look out of place on Android. For a richer application, however, this might have a jarring effect on users who expect their mobile application to have a particular look and feel.

Open Sourcing the Plugin

As a result, a BlinkUp plugin was successfully built and we are able to use it in a sample Cordova application. The plugin and sample application have been made publicly available on GitHub and released under an Apache 2.0 license. Also, keep an eye out for it on npm! Open sourcing this was quite intentional and we wanted to give back to the Electric Imp and Cordova community to help anyone de-risk their Cordova and Imp-based IoT projects. Fork it, play with it, and send your contributions to help improve it!

Tags:

Author Overview

Ayesha Khan

Ayesha is a Director of Engineering who leads a team of developers, QA specialists, and project managers and helps them to be exceptional at what they do. Ayesha believes that to empower her team means investing in each and every team member. Ayesha’s career in software has focussed on delivering mobile and web solutions that put the end user first. She thrives on bringing to life disruptive and cutting edge concepts. Some highlights include an industry disrupting dual screen Android phone, electronic health record applications that gave on-the-go providers access, and an instant messaging application used by millions. Ayesha holds a BA in Electrical Engineering with high distinction from Carleton University. An idea person and maker at heart you can be sure to find her working on something interesting at any given time.
Dan Lanthier

As one of Macadamian’s Development Managers, Daniel is an integral part of the software development team. Daniel has a solid background in software engineering. His expertise includes .NET applications, Azure Mobile Services, iOS, and Internet of Things (IoT) with Electric Imp and Particle solutions. When he’s not in the office managing his team, prototyping UI, or building mobile applications, you can find him on the slopes, enjoying downhill skiing.