Build your own wearable with IBM Watson IoT Platform and IBM Bluemix

Connect a Bluetooth-enabled wearable device kit to a mobile app and send sensor data to the IBM Watson IoT Platform cloud


Important:IBM Internet of Things Foundation (IoT Foundation) is now named IBM Watson IoT Platform. The Bluemix service names have also changed. This article was written using the previous names and the Bluemix classic interface. The content and images have not been updated. It is provided "as is." Given the rapid evolution of technology, some steps and illustrations may have changed as well.

Within the evolution of the Internet of Things (IoT), wearables are one of the fastest-growing segments. Wearable computing can take many forms, such as watches, fitness bracelets, glasses, and even clothing. We are living in exciting times when wearables can enable technology to seep into our lives in ways that larger computing devices and smartphones previously did not.

The potential uses and applications for wearable devices are limited only by the imagination of the designer. This tutorial takes you through the fundamental process of connecting a Bluetooth-enabled wearable device kit to a hybrid mobile app and sending sensor data into the IBM Internet of Things Foundation (IoT Foundation) cloud. When sensor data arrives at the IoT Foundation, IBM Bluemix can be used to trigger various flows based on the sensor data collected.

The basic approach

Figure 1 shows a typical architectural approach that can be used for designing a wearable that communicates with the cloud. Tracking wearables have many features for following and reporting on individual activities — generally by using communication with a smartphone or tablet-type device to display status and report data. As the technology and the marketplace for wearable devices continues to grow, so will the need to transmit this data to other services. This architectural approach represents only one of several methods that you can use to get sensor data from wearables into the cloud for processing.

Figure 1. Wearable-to-cloud architecture
Diagram of an architecture for wearable-cloud communication
Diagram of an architecture for wearable-cloud communication

Wearable hardware selection

Today's consumer wearable marketplace is blooming with different types of devices. Usually, the approach of low-energy communication from a wearable device to a smart device (such as a smartphone or tablet) is accurate for detecting the various types of activities a user might engage in daily. The quality and accuracy of device data collection is highly dependent on the number and class of sensors that are included within the device. This dependence poses a tricky balancing act for wearable developers, who must balance form factor, processing, battery life, and attractive user interfaces.

Introducing the WICED Sense Development Kit

From an inexpensive and do-it-yourself (DiY) perspective, the WICED Sense Development Kit from Broadcom is an affordable entry point to the ever-expanding IoT world. This kit is a suitable device selection for engineers, tinkerers, DiYers, and entrepreneurs who are prototyping wearable use cases.

WICED (pronounced wicked) stands for Wireless Internet Connectivity for Embedded Devices. The kit consists of a Bluetooth Low Energy (BLE) board and five sensors (eCompass, pressure, humidity and temperature, gyroscope, and accelerometer) and runs by using a 2032 coin cell battery. The board, sensors, and battery are housed in a sturdy plastic case (see Figure 2). These characteristics, which are combined with a small form factor, make the WICED Sense kit an attractive choice for experimentation. For the purposes of this tutorial, the WICED Sense kit serves as your wearable. Next, you see how to interface the WICED Sense wearable device to a hybrid mobile application.

Figure 2. WICED Sense Development Kit from Broadcom
Photo of the WICED Sense Development Kit
Photo of the WICED Sense Development Kit

What you need

You need a few items to continue with this tutorial:

  • A Broadcom WICED Sense Development Kit. You can use other sensor-tag kits, but this tutorial focuses on the WICED Sense.
  • Apache Cordova version 3.6.3 or newer.
  • A smart device (smartphone or tablet) with BLE capabilities. The tutorial uses an Android tablet that runs Android 4.4 (which has BLE capability).
  • An IBM Bluemix account so that you can use the IBM IoT Foundation and Node-Red. A free Bluemix trial is available.

See Download to get the source code for this tutorial.

Interfacing your wearable with a hybrid app

First, to read the data that is collected from the sensors on your WICED Sense wearable device, create a hybrid application with Apache Cordova. The hybrid app runs on your BLE-enabled smart device and bonds with the WICED Sense kit. When bonding is complete, your hybrid app can read all the readings from the sensors on the WICED Sense kit and send them to the IoT Foundation cloud.

Download the hybrid application source code and extract the compressed file into a folder of your choice (for example, WICED-Sense-IoT). All needed artifacts are provided, except for two files: easy-ble.js and mqttws31.js; download them now from the links that are provided here. Place easy-ble.js and mqttws31.js in the lib folder of the application.

The hybrid application is organized into the following files and folders:

  • index.html: The main application HTML file. It controls the loading of other JavaScript library files and serves the UI.
  • common.css: Holds any Cascading Style Sheets (CSS) markup that is needed for the application.
  • lib/easy-ble.js: JavaScript library that is used to simplify interfacing with BLE devices. Provided by Evothings.
  • lib/mqttws31.js: JavaScript library that enables a client to use the MQTT V3.1 protocol to connect to an MQTT-supporting messaging server. You use it to connect to the IBM IoT Foundation.
  • lib/WICED-Sense.js: JavaScript library for interfacing with the WICED Sense kit.
  • lib/iotFoundation.js: JavaScript library that simplifies interaction with the MQTT protocol and connection to the IBM IoT Foundation.

Before you start to customize the hybrid application, go into IBM Bluemix so that you can register your new WICED Sense wearable. By doing so, you enable the WICED Sense device to send sensor data to the cloud after the device is bonded to the hybrid app.

Getting into IBM Bluemix

Head over to Bluemix and create a free trial account if you don't already have an account. Log in to Bluemix. Now set up a new Node-RED application so that you can then establish an IoT Foundation service:

  1. In the Bluemix dashboard, click CREATE AN APP and select WEB as the type.
  2. Select Browse Sample Apps, click EXPLORE SAMPLES, and select Node-RED Starter from the Boilerplates category.
  3. In the Create an app dialog box on the right side, give your app a unique name (such as developerWorks-App) and click CREATE.
  4. Your Node-RED app is now provisioned. From the dashboard, click ADD A SERVICE.
  5. Scroll down to Internet of Things and click it to add the service.
  6. In the Add Service dialog box on the right, be sure that your Node-RED app is selected in the App: field. You can choose Free for the Selected Plan. Click CREATE.
  7. If prompted to restage your app, click RESTAGE.

Your application dashboard now looks similar to Figure 3.

Figure 3. Bluemix dashboard
Screen capture of newly created app in Bluemix dashboard
Screen capture of newly created app in Bluemix dashboard

Setting up the WICED Sense kit in the IoT Foundation

With the Internet of Things service that is bound to your Bluemix app, you can easily trigger flows from a device. But first you must register your WICED Sense device. As of this writing, the WICED Sense device is not a formal "recipe" in the IoT Foundation, so you'll improvise and add the device yourself:

  1. From the Bluemix dashboard, click the Internet of Things service, then click LAUNCH.
  2. From the IBM Internet of Things Foundation dashboard, click the Add Device link.
  3. In the Register Device form, Device Type is set to Create a Device Type. In the text box directly below the Device Type box, type WICED-Sense.
  4. In the Device ID text box, you can enter any unique identifier (for example, 8675309). You need this identifier later, so be sure to write it down. Click Continue.
  5. The next page presents you with important credentials for your newly registered WICED Sense device. Copy this information into a text file for safekeeping and then click Done.

Back to the hybrid app

So far, you've:

  • Created a Bluemix Node-RED app
  • Bonded the Node-RED app with the IoT Foundation
  • Registered your WICED Sense kit within the IoT Foundation

You can now turn your attention back to your hybrid application. Start by plugging in a few of the values that you generated from the IoT Foundation into the hybrid app so they can all communicate with one another:

  1. On your local file system, navigate to where you extracted the hybrid application source files.
  2. In a text editor, open the lib/iotFoundation.js file.
  3. At around line 17, locate a comment that tells you to enter the credential information you received from the IoT Foundation after you registered your WICED Sense device.
  4. Enter your values for: CLIENT_ID, ORG_ID, the first part of IOT_URL, and the IOT_PASS.
  5. Save any modified code.

Building your Cordova app

The final task in reading and processing your WICED Sense wearable sensor data is to build your hybrid app and to deploy and test it on a smart device. You can create and achieve many things with Apache Cordova. For the purposes of this tutorial, I cover only how to build the application.

With Apache Cordova installed, open a command window and perform the following steps:

  1. Type cordova create project-folder app-identifier app-name (for example: cordova create dw-project com.developerWorks.wiced WicedSenseApp).
  2. Change to your project directory:
    cd dw-project
  3. From within the project folder, delete the files in the www folder.
  4. Move or copy all the files from your hybrid app project into the www folder.
  5. Add the Evothings BLE plug-in:
    cordova plugin add com.evothings.ble
  6. Add the platform that you want to build for by typing either:
    cordova platform add ios
    cordova build ios

    cordova platform add android
    Type: cordova build android
  7. Deploy the code to the appropriate device and test.

You now have a hybrid app that runs on a BLE-capable smart device that can bond with your WICED Sense kit. When you run the hybrid app on your smart device, it looks similar to Figure 4.

Figure 4. Hybrid app
Screen capture of the running hybrid app
Screen capture of the running hybrid app

Testing your hybrid app

When you run the hybrid app, you can then start your WICED Sense tag. After your smart device detects the WICED Sense tag, you see the app Status indicate Sensors online. The hybrid app also opens a connection to the IBM IoT Foundation by using the smart device's Internet connection. Finally, WICED Sense sensor data is displayed on the screen as a series of numbers. As you move the WICED Sense tag, the numbers change.

The hybrid app is already coded to send a movement event to the IoT Foundation when the app senses that the WICED Sense tag is moving. Movement is defined as consistent movement of the WICED Sense tag for more than six seconds. As a test, put the battery in your WICED Sense tag. When it is detected by the hybrid app, move the WICED Sense tag in your hand for six or seven seconds. In the app, watch the Are You Moving? status change from false to true.

As the movement toggles to true, a movement event is sent to the IoT Foundation Cloud. Now, hold the WICED Sense tag as still as possible for six or seven seconds, and watch the Are You Moving? status revert to false. As the movement is toggled back to false, another event is sent to the IoT Foundation cloud. Repeat these actions to continue to send events into the IoT Foundation. To see the events, look in your IoT Foundation Devices dashboard (shown in Figure 5), which is accessible from your IBM Bluemix dashboard.

Figure 5. IoT Foundation Devices view
Screen capture of the IoT Foundation devices view
Screen capture of the IoT Foundation devices view

Things to do next

Now that you have sensor data that moves through the IoT Foundation, you can easily create a Node-RED application that acts on the movement data that is sent in. For example, you might send an SMS alert, write data to a database, or initiate any number of other actions.

Additionally, you might change the code to act on different sensors from within the WICED Sense kit. This tutorial uses the gyroscope to detect movement. You also might use the code from the tutorial to get readings from other sensors (such as the temperature or humidity sensors) and trigger events based on those readings.

Downloadable resources

Related topics


Sign in or register to add and subscribe to comments.

Zone=Big data and analytics, Mobile development, Cloud computing, Internet of Things
ArticleTitle=Build your own wearable with IBM Watson IoT Platform and IBM Bluemix