Creating A BlueMix IoT App

This is a short guide to creating your first IBM BlueMix App for an IoT application. In this guide we will demonstrate how to get data that has been published to the Internet of Things Foundation Service from a device and how to push data back to the device. We will use Node Red to create the applications functionality.

This guide assumes that:

  1. You have already created a IBM Bluemix account and have logged in so that you can see your Dashboard.
  2. You have an ESP8266 device connected to the internet and publishing temperature data to the Bluemix MQTT server.

This application will connect to a device that is registered to your Internet of Things Foundation Service in BlueMix. If you have not created a Internet of Things Foundation Service and added a device to it then you will need to do this first.

Creating the App

  1. From the Dashboard click the Create App Icon Screen Shot 2015-12-23 at 08.42.25
  2. Select Web application
  3. Select Browse Boilerplates
  4. Select Internet of Things Foundation StarterScreen Shot 2015-12-23 at 08.45.43
  5. Give your App a name and click Create

Screen Shot 2015-12-23 at 08.51.15

Your application will then be built. Wait for it to complete staging.

App Development

Once it is running click on the link for your app to be taken to the Node-RED landing page. This page gives information about getting started with Node-RED. We will proceed straight to the editor.

  1. Click the Go to you Node-RED flow editor Button. This will bring up a demo app that takes in the temperature from an attached device and set a warning based on the received temperature reading.

Adding the Bluemix IoT Service to your App

Before we link this to your device we need to bind the Internet of Things Service to this App.

  1. Go to the IBM Bluemix Dashboard for your app and select the overview tab for your app from the left hand menu.
  2. Select the + Bind Service or API button
  3. Check the Internet of Things iotf-service and click Add
  4. You will then click Restage to restart the app with the new settings

Giving the App Functionality

  1. Now go back the the Node-RED flow editor once the app has restaged.
  2. Double click on the IBM IoT App In node and edit the following fields:
    1. Authentication: BlueMix Service
    2. Input Type: Device Event
    3. Device Type: <Device type as entered when device was registered>
    4. Device Id: <Device ID as registered – usually MAC Address>
  3. Click OK
Settings for IBM IoT App In using the BlueMix Service

Settings for IBM IoT App In using the BlueMix Service

 

 

The App is now ready to deploy. Click the Deploy Button in the top right of the editor. If successful a pop up message will shortly appear.

To see the messages from the device select the Debug tab from the right hand side panel. Note if messages are not appearing first check if your device is successfully publishing mqtt messages, then check that the BlueMix server is receiving the devices in your Internet of Things foundation Dashboard. Finally refresh the Node-RED flow editor page.

The example flow assumes that you labelled the temperature attribute in your JSON message as “temp”. If this is not the case double click on the temp function node and edit the function to match your attribute name. E.g. if attribute is “temperature” edit to return {payload:msg.payload.d.temperature};

Now lets add some modes so that we can send a message back to the device.

  1. Drag on an Inject node from the input palette
  2. Drag on an IBMIoT node from the output palette
  3. Connect the Inject node to the IBMIoT node as shown below

Screen Shot 2015-12-23 at 10.25.31

 

 

 

  1. Double click the IBM IoT node and edit the following fields:
    1. Authentication: Bluemix Service
    2. Output Type: Device Command
    3. Device Type: <Device type as entered when device was registered>
    4. Device Id: <Device ID as registered – usually MAC Address>
    5. Command Type: <command name as defined on your device> e.g. light
    6. Format: json
    7. Data: <json command string> e.g. {“d”:{“light”:0}}

Screen Shot 2015-12-23 at 10.28.49

  1. Click OK
  2. Double click the Inject node and edit the following fields as shown below:
    1. Payload: string
    2. {“d”:{“light”:0}}
    3. Topic: Data

Screen Shot 2015-12-23 at 10.34.33

Once the changes are complete click Deploy to update your app.

You can now inject the command into the Bluemix MQTT server by clicking on the button that is on the left hand side on the Inject node. A pop up message will indicate that the message was successfully sent. You should see the received message in the serial console attached to your device.

For further information check out this guide from IBM

Advertisements