Contents


Overview

Skill Level: Intermediate

You need to know the basics around Bluemix, Watson IoT Platform, Sigfox, MQTT, Arduino programming and IoT.

This recipe describes how to connect an Arrow SmartEverything device to the Watson IoT Platform through the Sigfox backend and a Bluemix gateway. It will also show how to use it as a Weather Station, and show the measurements in a Node-Red dashboard.

Ingredients

  • A physical Arrow SmartEverything FOX device must be obtained, registered and connected to the Sigfox backend.
  • A Bluemix application based on the "Internet of Things Platform Starter" boilerplate.
  • Access to the Sigfox backend is required to setup the integration towards the Watson IoT Platform application in Bluemix.

Step-by-step

  1. Introduction

    This recipe is building on the content from another recipe: 
    Connecting Sigfox backend to Watson IoT Platform – by building an IoT Gateway in Bluemix.
    – with the following changes and additions:

    • We will add a new Device type and callback script in the Sigfox backend to reflect another device type in step 5
    • We will make changes to the Watson IoT Platform gateway in step 6 to change the device type.
    • We will make changes to the Watson IoT Platform application in step 7 to extract the SmartEverything data
      and visualize them in a node-red dashboard.

    You'll need to run through the other recipe before continuing with the next steps in this recipe, hence have access to the Sigfox backend and your Bluemix application with the Watson IoT Platform service working properly.

     

     

  2. SmartEverything: Prepare the device to be a weather station

    Download the User Guide for the Arrow SmartEverything here:
    http://docs-europe.electrocomponents.com/webdocs/144b/0900766b8144b09d.pdf

    Follow the steps in Chapter 5 of this User Guide in order to setup your development environment for the Arrow SmartEverything device.

    Then go to https://github.com/nicolsc/sigfox-weather-station to get the code and instructions for the
    Weather Station – Thank you to Nicolas Lesconnec from Sigfox to provide this code.

    You should now be up and running with the weather station on your Arrow SmartEverything utilizing the Sigfox network to submit the following data in the 12 bytes available every 10 mintues:

    • Pressure in mbar
    • Temperature in °C
    • Humidity in %

     

  3. Sigfox: Create new Device type and callback script

     

    1. Go to the Sigfox Backend, where you login with your credentials and go to the Device Type tab:
      41-Callback-21
    2. Click on New in the upper right corner in case you haven't already created a device type for your SmartEverything, and fill in the details for this new device type, e.g. like this:
      300-SmartEverything-Sigfox-setup-2
      Click on OK.
    3. Go to the Callbacks section:
      43-Callback-21
    4. Follow step 5.4-5.7 in the other recipe: 
      Connecting Sigfox backend to Watson IoT Platform – by building an IoT Gateway in Bluemix.
      Then add the content to the Body in order to send over the parameters available
      + the device type, so you can use that in the Gateway:
      {
      "time" : "{time}",
      "deviceType": "SmartEverything",
      "device" : "{device}",
      "duplicate" : "{duplicate}",
      "snr" : "{snr}",
      "rssi" : "{rssi}",
      "avgSnr" : "{avgSnr}",
      "station" : "{station}",
      "lat" : "{lat}",
      "lng" : "{lng}",
      "seqNumber" : "{seqNumber}",
      "data" : "{data}"
      }

      – and we are done creating the callback:
      302-SmartEverything-Sigfox-setup

    5. Click on OK
    6. Add your device as this Device type using the Device ID and PAC provided with the SmartEverything device.

    The device is now properly configured in the Sigfox backend to send data over to the Watson IoT Platform.

     

  4. WIoTP: Edit the IoT Gateway in Node-Red to extract device type from message

    At the end of step 6 in the other recipe, the flow for the Gateway looked like this:

    67-GW1

    We will now edit the Resend as Gateway function node to reflect the SmartEverything device type.

    1. Double click the function node and change the line that define the deviceType, so it looks like this:
      102-GW-Change1
    2. Deploy the application. A new deviceType will be created at the Watson IoT Platform called SmartEverything and new data flowing in from that specific deviceType in the Sigfox backend will be accessible.
      Go to the Device tab at your Watson IoT Platform of your application and you will see that your device have been auto registered with the new deviceType (once it have send some data):
      313-SmartEverything-GW-setup

     

  5. WIoTP: Edit the "IoT Platform" Node-Red flow for receiving the SmartEverything data

    At the end of step 7 in the other recipe, the flow for the IoT Platform looked like this:

     73-Normal-flow

    We will now change this flow to receive MQTT messages for the devices of the SmartEverything device type and extract the data for temperature, humidity and barometric pressure.

    1. Double click the IBM IoT node and change Device Type to SmartEverything and click Done:
      321-SmartEverything-Flow-setup
    2. Add a function node and add the following code to decode the SmartEverything data
      (including temperature, humidity and barometric pressure):
      323-SmartEverything-Flow-setup

      I've added the below code in textual form, to make it easier for you to create your “Retrieve SmartEverything information” function node:

      var seData = msg.payload.d.data;

      var pressure = parseInt(seData.substring(0,8),16);
      msg.payload.d.pressure = pressure.toString();

      var humidity = parseInt(seData.substring(16,24),16);
      msg.payload.d.humidity = humidity.toString();

      var tempStr = '0x' + seData.substring(8,16);
      var temp = parseFloatOwn(tempStr);
      msg.payload.d.temp = temp.toFixed(2);

      return msg;

      // Functions:
      function parseFloatOwn(str) {
      var float = 0, sign, order, mantiss,exp,
      int = 0, multi = 1;
      if (/^0x/.exec(str)) {
      int = parseInt(str,16);
      }else{
      for (var i = str.length -1; i >=0; i -= 1) {
      if (str.charCodeAt(i)>255) {
      console.log('Wrong string parametr');
      return false;
      }
      int += str.charCodeAt(i) * multi;
      multi *= 256;
      }
      }
      sign = (int>>>31)?-1:1;
      exp = (int >>> 23 & 0xff) - 127;
      mantiss = ((int & 0x7fffff) + 0x800000).toString(2);
      for (i=0; i<mantiss.length; i+=1){
      float += parseInt(mantiss[i])? Math.pow(2,exp):0;
      exp--;
      }
      return float*sign;
      }
    3. Drag in another debug node and change it to Output: comlete msg object. Connect the additional nodes to the existing flow and optionally rename the two debug nodes:
      324-SmartEverything-Flow-setup
    4. Deploy the application and wait until a new message is received and then compare the two debug messages.

      The “IoT Platform received” debug node output shows the raw data (“0000040a41cfc7520000002d”) and the new deviceType (“SmartEverything”):
      325-SmartEverything-Flow-setup

      The “SmartEverything Data” debug node output shows the added extracted data added by the function node:
      326-SmartEverything-Flow-setup

  6. WIoTP: Edit the "IoT Platform" Node-Red flow to visualize the SmartEverything data

    We'll use the node-red-dashboard capabilities to visualize the extracted data from the SmartEverything device on a dashboard. First we have to add that library to your application:

    1. Go to the Node-red editor of your application, e.g. http://sigfoxgw.eu-gb.mybluemix.net/red.
      Select Manage palette in the right menu:
      201-Palette2
    2. Press the Install tab:
      202-Palette2
    3. Write “node-red-dashboard” in the search field and then press “install” once the node-red-dashboard library is found:
      01-12-New-Dashboard
    4. Wait until the nodes has been added:
      212-Palette1
    5. Press Done:
      205-Palette2
    6. Reload the web page and scroll down to the bottom of the nodes and you will now see this:
      213-Palette1

    Then we are ready to use the newly added Dashboard capabilities in our application.
    The following steps will guide you to change the “IoT Platform” flow to look like this:
    332-SmartEverything-Dashboard-setup

    1. First add the three function nodes and connect them to the “Retrieve SmartEverything information”
      function node:

      Extract Temperature – the msg.topic value will be shown in the chart node replacing “data”:
      333-SmartEverything-Dashboard-setup

      – in text:

      msg.payload = msg.payload.d.temp;
      msg.topic = "Temperature";
      return msg;

      Extract Humidity:
      334-SmartEverything-Dashboard-setup

      – in text:

      msg.payload = msg.payload.d.humidity;
      msg.topic = "Humidity";
      return msg;

      Extract Pressure:
      335-SmartEverything-Dashboard-setup

      – in text:

      return {payload:msg.payload.d.pressure};
    2. Deploy the application. Drag in a dashboard chart node and start configuring it
      by adding a new Group to the dashboard – click at the pencil:
      01-1-New-Dashboard
    3. We need to create the first Tab by clicking the pencil:
      01-2-New-Dashboard
    4. Give it a name like SmartEverything:
      01-3-New-Dashboard1
    5. Press Add. Change the Width to 10 and give it a Name, e.g. Indoor 1:
      01-4-New-Dashboard
    6. Press Add. Label it Temperature, change the X-axis to last 2 days,
      and define a custom X-axis Label as “Y-MM-DD – HH:mm:ss”:
      01-5-New-Dashboard
    7. Press Done and connect the chart node to the “Extract Temperature” function node.
      Add another Chart node. Label it Humidity, change the X-axis to last 2 days, 
      and define a custom X-axis Label as “Y-MM-DD – HH:mm:ss”:
      01-11-New-Dashboard
    8. Press Done and connect the chart node to the “Extract Humidity” function node.
      Drag in a dashboard gauge node and connect it to the “Extract Temperature” function node.
      Configure the gauge node: change the Group to “Add new ui_group” and press the pencil:
      134-IoT-Platform-UI
    9. Give it another name, e.g. Indoor 2:
      01-6-New-Dashboard

    10. Press Add. Change Title to Temperature. Change Label to C. Change Range to 0-50.
      Optionally change the Color gradients:
      01-7-New-Dashboard
    11. Press Done. Drag in a dashboard gauge node and connect it to the “Extract Humidity” function node.
      Change Group to Indoor 2. Change Title to Humidity. Change Label to %. Change Range to 0-100.
      Optionally change the Color gradients:
      01-8-New-Dashboard
    12. Press Done. Drag in a dashboard gauge node and connect it to the “Extract Pressure” function node.
      Change Group to Indoor 2. Change Title to Pressure. Change Label to mbar. Change Range to 800-1200.
      Optionally change the Color gradients:

      01-9-New-Dashboard

    13. Press Done. Select the dashboard tab in the upper right corner. Select the Dark Theme.
      Optionally change the Title.
      Expand the two Groups and this is what you should see:
      01-10-New-Dashboard
    14. Deploy the application.
    15. You access the dashboard by changing the url in your browser to point at /ui in your bluemix application,
      e.g. http://sigfoxgw.eu-gb.mybluemix.net/ui.
      Enough data has flown in after two days and the dashboard could look like this:
      01-15-New-Dashboard

      Note: Moving the cursor into the Temperature chart shows the measured temperature at a give time.
      The format is defined by the msg.topic =”Temperature”; in step 1 and the customized X-axis Label in step 6. 

  7. Conclusion

    This recipe is building on the content from another recipe: 
    Connecting Sigfox backend to Watson IoT Platform – by building an IoT Gateway in Bluemix.

    – where we have:

    • added a SmartEverything device and distinguised it with a separate deviceType which was auto generated in the Watson IoT Platform.
    • decoded the temperature, humidity and barometric pressure information from the data transmitted form the Arrow SmartEverything.
    • visualized the extracted information on a dashboard.

    NB: Future updates of both IBM Bluemix, node-red, the node-red nodes, and the Sigfox backend might slightly impact the screen captures.

     

  8. History

    ==============================================================================
    | DATE | COMMENTS |
    ==============================================================================
    | 2016-12-18 | First release. |
    | 2016-12-20 | Updated according to new version of the node-red-dashboard, |
    | | which was updated from 2.1.0 to 2.2.0 with changed UI |
    | | and date formats (now based on Moment.js). |
    | | Corrected some other minor errors. |
    | | |
    ==============================================================================

2 comments on"Connect an Arrow SmartEverything device to the Watson IoT Platform"

  1. Hi Jan

    Firstly thanks for the post. I carefully followed your instructions but I’m stuck at step 4, where I cannot see any incoming data into the debug node of my node-RED app.
    In my Sigfox Backend profile, if I go to my callback I can see “Not allowed” – 403 error for every message sent. It seems like IBM server refuse the message of my Smarteverything…

    I filled all fields properly using my Org ID, device Authentication Token, device type& name, etc but it does not work. Any clue on this issue?
    I also tried the following tutorial https://developer.ibm.com/recipes/tutorials/connecting-a-sigfox-device/ which use API key and token but doesn’t work.

    Could you please help me out?
    Thanks a lot

    Simone

    • Hi Simone

      I would double check the credentials of the AuthDevice as it seems like you cannot connect to the Watson IoT Platform.
      Are you using another type/id/password for the authentication device?

      Kind Regards
      Jan

Join The Discussion