Overview

Skill Level: Beginner

Beginner

Introduction The Watson IoT Node is a pair of Node-RED nodes for connecting your device to the IBM Watson Internet of Things Platform as a Device or as a Gateway. In this recipe, you will learnHow to install Watson IoT Node in Raspberry Pi,Connect the Raspberry Pi, as a device to the IBM Watson IoT […]

Ingredients

Hardware

1. Raspberry Pi Model B/ Model B+/  2

2. Minimim 8GB SD card with latest Rasbian operating system(Raspberry Jessie or higher)

Step-by-step

  1. Introduction

    The Watson IoT Node is a pair of Node-RED nodes for connecting your device to the IBM Watson Internet of Things Platform as a Device or as a Gateway.

     

    In this recipe, you will learn

    1. How to install Watson IoT Node in Raspberry Pi,
    2. Connect the Raspberry Pi, as a device to the IBM Watson IoT Platform, and
    3. Learn how to send events to the platform and receive commands from it.

     

    For more information about the Watson IoT Node please click here.

  2. Watson IoT Node on Raspbian Jessie

    The latest version of Raspbian Jessie has both Node-RED and Watson IoT node pre-installed. So you can skip this step.

     

    If you already have an older version of Jessie, you can install or upgrade Node-RED using the standard package manager:

    sudo apt-get update
    sudo apt-get install nodered

     

    At this stage we have installed Watson IoT Node in Raspberry Pi.

  3. Starting Node-RED

    To start Node-RED, there are two ways:

    1. on the Desktop, select Menu -> Programming -> Node-RED.
    2. run the following command in a new terminal window.
       node-red-start

    To stop Node-RED, run the following command in a new terminal window:

     node-red-stop

     

    You can then access the Node-RED editor by entering http://localhost:1880 in the browser address of Raspberry Pi.

    To connect to the Node-RED editor via network:

    Once Node-RED is running – open the browser program in the host machine and then browse the address http://{the-ip-address-returned}:1880/. One way to find the IP address of the Pi is to use the command

     hostname -I

     

    Autostart on boot:

    To have the Node-RED application started, when the Pi system boots, please refer to the steps mentioned against the page Running the Node-RED, on the nodered.org site.

     

    After this step you will be able to access Node-RED editor, with the Watson IoT Nodes, in it using which you can send events to the IBM Watson IoT Platform and receive commands from the same.

  4. Sending Device Events to Watson IoT Platform [Quick Start]

     

    • In the Node-RED editor, which you have opened in the browser (either on Raspberry Pi or on the host system), click on Menu – > Import -> Clipboard
    • Copy the json from this link and paste it in the clip board
    • Click on Ok button then place the flow in the work place
    • Click on deploy button to start

     

    Now the CPU temperature from your Raspberry Pi is sent to the Watson IoT Platform once every 5 seconds. You can also verify that in the debug tab.

     

    Click here to open the QuickStart Dashboard

  5. Registering your Device In Watson IoT Platform

     

    To explore and make use of the full capabilities of Watson IoT Platform (including bidrectional flow), we need to setup and register your device(s) in the platform. This section shows how you can setup the same.

     

    Carry out the steps present in this recipe to register your device(s) in IBM Watson Internet of Things Platform.

     

    At this step, we have successfully created the Watson IoT service and registered your device(s) in it.

     

  6. Sending Device Events to Watson IoT Platform [Registered]

     

    Once you have registered your device in the Watson IoT organization make the following modification in quick start flow.

    • Double click on the event node.

    • Select connection as Registered .

    • Select edit button in Credentials.

    • Fill the Organization,Device Type, Device ID, Auth Token and then click on the Add button.

    • Click on the Ok Button.
    • Click on deploy button to start.

     

    Now Node-RED flow will start sending events to your organization.

     

  7. Receiving Device Commands From Watson IoT Platform

     

    In order to receive commands from the IBM Watson IoT Platform we need to register our device to the Platfor. Please follow the step Register Your Device in Watson IoT Platform given above.

     

    • In the Node-RED editor, which you have opened in the browser (either on Raspberry Pi or on the host system), click on Menu-> Import – >Clipboard.
    • Copy the json from this link and paste it in that clip board.
    • Click on Ok button then place the flow in the work place.
    • Double click on cmd receiver.

    • Select edit button in Credentials.

     

    • Fill the Organization, Device Type, Device ID, Auth Token and then click on update button.

     

    • Click on the Ok Button.
    • Click on the deploy button to start the flow.

     

    Note : You will need an external application that is sending commands to this Raspberry Pi Device.

     

    Now you can receive the commands from Watson IoT Platform which will be displayed in the debug tab.

  8. Conclusion

    Now we have seen how to deploy Watson IoT Node in the Raspberry Pi as a device and send events to the IBM Watson IoT Platform and receive commands from the Platform using Node-RED without any programing.

     

  9. Where to go from here?

    The next part of the recipe shows how to use the Raspberry Pi work as a gateway.

2 comments on"Connecting Raspberry Pi as a Device to Watson IoT using Node-RED"

  1. The_screen_name January 06, 2017

    Raspberry autostart command no longer valid

  2. I would like to transfer one file from raspberry pi environment in to one generator, which has usb port only. So how can i send this file in to usb port of the generator by using node red

Join The Discussion