Skip to content

Sample application that demonstrates how to use Electric Imp's BlinkUP SDK in Cordova applications

License

Notifications You must be signed in to change notification settings

Macadamian/Cordova-BlinkUpSample

Repository files navigation

Cordova-BlinkUpSample

Sample application that demonstrates how to use the BlinkUp Cordova plugin or NPM to integrate Electric Imp's BlinkUp SDK with Cordova applications for iOS and Android. Refer to the plugin repository or NPM for more information about the plugin and how to install it in your own project.

Note: this repository simply shows an example of how you can integrate the plugin and interface with it from a Cordova project. Any modifications to the native plugin code should be done on the plugin repo at https://github.com/Macadamian/Cordova-BlinkUpPlugin.

Electric Imp is an Internet of Things platform used from prototyping to production. For more information about Electric Imp, visit: https://electricimp.com/.

Prerequisites

An Electric Imp Board development kit. For more information on how to obtain a development kit, please visit: https://electricimp.com/docs/gettingstarted/devkits/

An Electric Imp developer account. To register for an account, please visit: https://ide.electricimp.com/

A BlinkUp SDK and API Key. For more information on how to obtain a license, please visit: https://electricimp.com/docs/manufacturing/blinkup_faqs/

Xcode, Android Studio, and cordova are required.

Installation

It is recommended to build the project from the command line to start for iOS cordova build ios and Android cordova build android. This step will initially fail, due to missing prerequisites.

iOS Instructions
Copy the BlinkUp.embeddedframework folder to path/to/Cordova-BlinkUpSample/platforms/ios/CordovaBlinkUpSample/Frameworks folder.

Android Instructions
Copy the blinkup_sdk contents (.jar or .aar file) from the BlinkUp SDK to path/to/Cordova-BlinkUpSample/platforms/android/libs.

Important
You need to create a file called CordovaBlinkUpSample/www/js/blinkupconfig.js based on CordovaBlinkUpSample/www/js/blinkupconfig.example. This file is generated by the Xcode and/or Android Studio build. Open CordovaBlinkUpSample/www/js/blinkupconfig.js and set your API key from Electric Imp. You can optionally set your development plan ID as well, this will let you see Imps you've blinked up with in your IDE. Please read testing the plugin before setting a development plan ID, as it can prevent users from connecting to wifi if it makes it into production code.

When building, the root index.js file overwrites the native platform's index.js file, propagating your changes down to both platforms.

Running Sample Application

Once you have updated your plugin with the library, and provide your API key, you can run the application from within Xcode or Android Studio, or from the command line using cordova run ios or cordova run android. Make sure to run cordova prepare <platform> at least once before using Xcode or Android Studio.

Project Structure

Refer to www/index.js for an example of how to call the plugin that initiates the native BlinkUp process.

The native code that interfaces with the plugin (and sends back the device info) can be found at platforms/android/src/com/macadamian/blinkup and platforms/ios/CordovaBlinkUpExample/Plugins/com.macadamian.blinkup.

Testing the Plugin

If you are testing devices for development, you can input your own development planID to see the Imps in the Electric Imp IDE. Just set it at the top of the index.js files and ensure you pass false for generateNewPlanId. The development plan ID you set will override a cached plan ID (if there is one) if generateNewPlanId is false. If generateNewPlanId is true however, a new plan ID will be generated every BlinkUp and the development plan ID will be ignored.

When you pass in a development plan ID, the plugin will not cache it. Caching is only done on production plan ID's, and is used to save user settings across BlinkUp's (e.g. when they change their wifi password).

IMPORTANT NOTE: if a development plan ID makes it into production, the consumer's device will not configure, and will be unable to connect to wifi. There is a check in the native code on each platform which will ignore a development plan ID if the build configuration is set to release, but it is best to remove all references to the plan ID and pass an empty string from the Javascript when you're done debugging. Please read http://electricimp.com/docs/manufacturing/planids/ for more info.

Updating the Plugin in the Sample application

To update the native plugin files to the latest from NPM, simply run the update script, UpdatePlugin.sh. This will overwrite all the native plugin files in platforms/ios/CordovaBlinkUpSample/Plugins/com.macadamian.blinkup and platforms/android/src/com/macadmian/blinkup. If you have made changes to any of those files, do not update. It is instead recommended that you clone the plugin repo and make changes off of that.