Skill Level: Beginner

Connected Devices form the core of Internet of Things. The IoT solutions and there in, the business, are dependent on their active participation. Hence, it is critical to monitor their connection status at regular intervals & alert relevant personnel


Software Requirements



  1. Introduction

    In an enterprise organisation, you would always find ‘n’ number of Devices, belonging to ‘m’ number of Device Types. A combination of Device-ID and Device-Type uniquely defines the Device across the organization. Monitoring the connection status of the Device forms a critical criteria, to ensure the stability and robustness of the IoT solution. 

    Illustration of Device connection status – connected or disconnected, and if disconnected, then, reason behind the down time issue, if portrayed and provided in a simple dashboard, makes the life a lot easier, to monitor the Device and further debug, in case of Device connection going down.

    Device Status Sample provides a simple approach to access a Device Status Dashboard, that lists out the connection statistics of various Devices associated with Device-Types, that are registered to the Watson IoT Platform.

    The source code for the Device Status sample is written in Node.js using Node.js Client Library and has been made available on the Github Repository. Refer to the WIoTP Documentation to further understand the IBM Watson IoT Platform capabilities, to come up with your own Application, Device & Gateway samples in the world of Internet of Things.

  2. What is demonstrated in this Recipe

    This recipe is intended to simplify the process of monitoring the Device Status, by providing a Device Status Dashboard, that lists out all the Device-Types and the Device-ID’s associated with each of them, as registered on the Watson IoT Platform (WIoTP).

    The Dashboard, currently lists the following:

    • Device-ID                    : Unique Device-ID associated to a given Device-Type
    • Device-Type               : Unique Device-Type that hosts a Device or a set of Devices
    • Connection Status    : Specifies whether the Device is Connected to the WIoT Platform or not
    • Close-Code                : Specifies the Close-Code, if the Device is Disconnected from the WIoT Platform
    • Reason                       : Specifies the Reason associated with the Close Code, that caused the disconnection
    • Client-Address       : The last known IP Address of the Device, before it got disconnected from the WIoT Platform


  3. Deploy Node.js Application along with Watson IoT Platform on Bluemix

    This section helps you with the steps to Deploy the Node.js application and the associated Watson IoT Platform, as a service, on Bluemix.

    The following set of steps, shall walk you through the deployment process:

    1. The Device Status sample is made availabe on the Github repository. Click on the Create Toolchain button, provided below, to initiate the deployment process of deploying the Node.js service, that hosts the Device Status sample.


      Note: If you are a User using the United Kingdom Region in your Bluemix environment, then please make use of the following Deploy to Bluemix button, to deploy the setup under your United Kingdom Region. Users of US South Region can ignore this step.


    2. You should now get to see the Deploy to Bluemix screen. Choose the Organization of choice and a custom name to your Application. Click on Create to go ahead and deploy the mentioned service(s) to Bluemix.


    3. With the Deployment process concluding successfully, you can now access the Device Status sample application, by clicking on the “View Your App” link. Alternatively, you can always access the Application from the application service available on Bluemix Dashboard.

    In this section, you were briefed on the steps that helped you Deploy the Device Status sample successfully on the Bluemix platform and open up / access the Device Status Dashboard, using the Application link / URL.

  4. Register your Device In Watson IoT Platform

    The section helps you register the device to Watson IoT Platform and obtain the credentials, in order to publish the device events on to the Watson IoT Platform dashboard

    In order to access the full capabilities of the IBM Watson IoT Platform you must create an organization and register one or more devices in it.

    Open the Bluemix Dashboard and click on the Application service that you have currently deployed, if you have already moved away from it. You should see the Watson IoT Platform listed under the Binded Services. Click on the WIoTP service and choose the click on Launch button to launch the WIoTP Dashboard.

    Carry out the steps present in this recipe to register your device(s) in IBM Watson Internet of Things Platform. Once successfully registered, you should obtain the device credentials as well generate API Key. Note them down to work with the Device Status sample, during the scope of this recipe.

    This section explained how you can register devices using the dashboard and obtain security credentials.

  5. Accessing & Navigating through Device Status Application

    In this section, you shall be introduced to the steps that shall help you to access the Device Status Dashboard and navigate through the Device Status application using various options available.

    1. In the earlier section Deploy Node.js Application along with Watson IoT Platform on Bluemix, you had successfully deployed the Device Status Application on Bluemix. Step 6 of the section helped you with options to access the application. Click on the ‘View Your App’ or click the Application URL as available against the application service on Bluemix Dashboard, to open up the Device Sample Application.
    2. The Device Sample Application should now present the Welcome screen on the browser tab, as shown in the following image, prompting you ( User ) to authenticate and log in, to access the Device Status Dashboard. Use the API Key and Authentication Token to authenticate yourself and log in successfully.


    3. Once the authentication is successful, you should be presented with the Device Status Dashboard, as shown in the below image:

      Any set of Device-Types and Device-ID’s that are registered to the Watson IoT Platform, would be populated on the Dashboard, by default.

    4. Make use of the Device-Type Drop Down Menu to pull down the entire list of Device-Types that are registered onto the WIoTP, to narrow down your view to a particular Device-Type of interest.


    5. A choice of Device-Type made from the drop down menu in the above step, should now list all the Device-ID’s that are associated to the chosen Device-Type and their current status on the Dashboard


    6. If you are interested in only a specific Device-ID, then you can further refine your query by entering the name of the Device-ID of interest, in the TEXT Box provided against ‘Refine Your Search’ option, as shown below:


    The entries on the Device Status Dashboard continues to grow, as more and more number of Devices get registered on to the Watson IoT Platform. You get to monitor their current status, various close codes that helps you debug the issue and work towards successful conditioning of the Devices in an enterprise environment.



  6. What happened behind the scenes?

    In this section, you shall be taken through the application code, that helped you fetch the Device Status, as you clicked through the Device-Type(s) and then filtered through for a specific Device-ID, in the Device Status Application.

    The Watson IoT Platform has several built-in functions, that, as an Application Developer, you can leverage, to query against the platform components as well perform operations, which are otherwise tricky to handle from application alone.

    This recipe makes use of one such function – appClient.subscribeToDeviceStatus(), described in detail, in the section Subscribing to Device Status. Subscribing to Device Status allows you to subscribe to status updates for all connected devices. It takes in Device-Type and Device-ID parameters to control the scope of the subscription. In all, a single client can support multiple subscriptions. 

    The code template mentioned below, allows you to do the following:

    1. Use the authentication credentials and initiate a Connection
    2. On successfully connecting to the WIoTP, executes the function appClient.subscribeToDeviceStatus(), to obtain the Status
    3. Reads the Status and prints the obtained payload, accordingly
      appClient.connect();appClient.on("connect", function () {appClient.subscribeToDeviceStatus("myDeviceType","myDeviceID");});appClient.on("deviceStatus", function (deviceType, deviceId, payload, topic) {console.log("Device status from :: "+deviceType+" : "+deviceId+" with payload : "+payload);});

    Now, if you follow the Device Status Sample as available on the Github repository, the index.js file lists out the execution of appClient.subscribeToDeviceStatus() at line # 77. So basically, the Device-Type (or the Gateway-Type) that you chose from the drop down menu and the Device-Id that you chose to filter, are passed as parameter values to the appClient.subscribeToDeviceStatus(), to complete the execution and fetch you the desired results.

    Detailed documentation on Watson IoT Platform and Node.js for Application Developers are made available. Refer to them to enhance your understanding on the nuances of IBM Watson IoT Platform.

  7. Conclusion

    The recipe demonstrated successful deployment of the Device Status Application that helped to monitor the connection status of various devices that are registered to Watson IoT Platform. Understanding the connection details of the Devices and their current status, helps identify the cause of the issue, reduce debug time and enhances the robustness of the IoT Solution.

    The Device Status Application can be further tweaked, to pull out additional details wrt connection, such as, Connection Initiated Time, Last Known Connection Time, Client ID, was the Connection Secure, Connection Protocol, Bytes Read & Bytes Written. You can make use of the Device Status sample to further enhance the application, based on the need and requirement of the organization.

    Note: The sample IoT application deployed at the end of this Recipe is only a prototype. Further, the IoT Recipe and the associated source code provide a head start to the IoT Developer with a sample application to build on top of it, to suit and meet the needs of the organization. It needs further enhancements/refinements to make it production ready. It only provides food for thought, opening up the possibilities that can be achieved by following this IoT Recipe. 

Join The Discussion