Overview

Skill Level: Beginner

A guide on how to connect the BB-400, an industrial, IoT, edge controller powered by a Raspberry Pi and an Arduino, to IBM cloud. Examples will be provided on how to send and receive data from a serial port and IO lines using Node-RED.

Ingredients

  • A BB-400 (Node-RED is setup on the device by default)
  • IBM Cloud account
  • IBM Watson IoT Platform

Step-by-step

  1. Introduction

    Brainboxes, established in 1984, is a British designer and manufacturer of data and I/O connectivity products.
    In 2019 Brainboxes launched the BB-400; an industrial, IoT, edge controller powered by a Raspberry Pi and an Arduino.

    bb-400-print

    The BB-400 contains 8 Digital IO lines, Bluetooth, WiFi, 2 Ethernet ports and an RS232/422/485 serial port. The BB-400 allows multiple connections within a compact DIN mount design. It is possible to use the BB-400 to process data locally and send it to the cloud. In addition, the BB-400 is preloaded with secure web admin and Node-RED, which makes it even easier to connect to IBM cloud and send/receive data from your device and the cloud.
    For more information about the BB-400 including links to purchase the device, please refer to the BB-400 product page. 

    This recipe will guide you through connecting your BB-400 to IBM Cloud, setting up your Node-RED flows for sending IO and serial data, and also setting up an IBM Node-RED instance to send and receive data from your device. 

     

  2. Add the BB-400 to the IBM Watson IoT Platform

    As listed in the prerequisite stages, please ensure that you have created an IBM Cloud account: https://cloud.ibm.com/, as well as an IBM Watson IoT Platform.

    Once you have completed those stages, you can launch the IBM Watson IoT Platform and add your device to the platform by clicking the “Add Device” button at the top of the screen.

    1. Identity

    The first step is to add information regarding your device type and assigning your device a unique ID.

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-AddDevice_Name_IoTPlatformWe have provided the device ID as BB-400-XXXX where XXXX are the last 4 digits of the device’s MAC address but feel free to assign an ID you deem suitable for your device.¬†

    2. Device Information

    You can provide device information in the next section, but it is fine to keep all the boxes blank and proceed to the next section.

    3. Security

    The next stage is to create a device authentication token. You can choose to either auto-generate a token or provide your own authentication token.
    It is very important that you keep a note of your token when it appears on the summary screen because when you proceed past the summary stage the token will not appear again.

    Review the information provided so far before the authentication token is created.

    4. Summary

    The summary page provides an overview of your device’s credentials. You will need the credentials for connecting your device to the IBM Watson IoT Platform. As mentioned previously, it is important to keep a note of your authentication token as you will not be able to recover its details when proceeding past this stage.

    You should now see your device on the IBM Watson IoT Platform device section:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-AddDevice_CompleteSummaryInfo_IoTPlatform

  3. Create Node-RED app

    Now you have added your device to the IBM Watson IoT Platform, the next step is to create a IBM Cloud Node-RED application to connect to your device’s Node-RED instance.

    Navigate back to IBM cloud and click on “Create resource”, within “Starter Kits” you will find the Node-RED Starter application.¬†

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-Node-REDapp-create

    Follow the instructions to create your Node-RED application.

  4. Connect IBM Watson IoT Platform to your IBM Cloud Node-RED application:

    Once your IBM Node-RED application has been created it is important to connect your IBM Watson IoT Platform to the Node-RED application so that you can connect your device as a registered device.

    You can open Node-RED by clicking on “Visit App URL”, this will take you to your IBM Cloud Node-RED instance and you can now start creating flows.

    At this stage you should have setup an IBM cloud account, an IBM Watson IoT platform and a IBM Node-RED application. We have also added our device to the IoT platform.

    The next section will explain how to connect your BB-400 to the IBM cloud’s Node-RED application. A basic example will be provided so you can send data to the IBM cloud and IBM cloud will receive the data.

  5. Open your BB-400 and IBM cloud Node-RED applications

    First we need to connect the BB-400’s Node-RED to the IBM Cloud’s Node-RED.

    In a web browser open up your BB-400’s Node-RED instance by selecting the apps section on the BB-400 web admin page or by typing in¬†http://YOUR-BB400-IP-ADDRESS:1880/;¬†¬†the port number for Node-RED is 1880.

    You can open up the IBM Cloud’s Node-RED by going to IBM Cloud, clicking on the Navigation Menu, and selecting Resource List.

    Under Cloud Foundry Apps you will find your Node-RED starter.

    Alternatively, type the following link into your browser: https://YOUR-NODE-RED-APP-NAME.eu-gb.mybluemix.net/red/ where YOUR-NODE-RED-APP-NAME is the name you assigned to your Node-RED starter app.

  6. Installing Watson IoT nodes

    The Watson IoT nodes are available by default on your BB-400 Node-RED application, you can find them on the left-hand side of your workspace.

    There are 2 Watson IoT nodes: input Node-REDapp-watson-iot-node and output Node-REDapp-watson-output-node. 

     

  7. Example 1: Sending BB-400's IO status to IBM's Node-RED instance using WebSocket

    The following example is a tutorial on connecting your BB-400’s Node-RED instance to IBM’s Node-RED application and also sending the BB-400’s IO status to the IBM Cloud using Node-RED via WebSocket.

    Open up your BB-400’s Node-RED instance.
    The first node you should add to your workspace is a WebSocket input node How-do-i-connect-the-bb-400-to-amazon-web-services-websocket-input-node and configure the node as follows:

     

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-websocket-node

    Note that 8989 is the port number for WebSocket.

    Next drag a json node How-do-i-connect-the-bb-400-to-fred-json-node onto the workspace and connect it to the WebSocket node.

    Then add a Watson IoT output node Node-REDapp-watson-output-node, double clicking on the node will show the following:

     

    how-do-i-connect-bb-400-to-ibm-watson-using-node-red-watson-iot-out-node-config

    Click on¬†“Registered” mode. Click on the pencil next to Credentials and fill in your device credentials.

    Node-REDapp-watson-output-node-config-register-credentials

    Finally add a debug node Node-REDapp-watson-debug-node so that you can see the output and finally connect it to the json node.

     

    The complete flow looks as follows:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-bb-400-complete-flow

    If we navigate to IBM Watson -> Devices -> Click on our device -> Recent Events, we can see the messages being sent to the IBM Cloud.

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-ibm-cloud-messages

    In addition, when we adjust the IO status, for example on the BB-400 web admin page and we¬†can see the change in IO status being sent from the BB-400’s Node-RED instance to the IBM Cloud.

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-toggling-io-lines-webadmin

  8. Receiving messages on IBM Cloud's Node-RED

    Next, we will configure IBM Cloud’s instance of Node-RED so that we can read the messages being sent from the BB-400’s instance of Node-RED.

    Drag an ibmiot node  Node-REDapp-watson-ibmiot-node and change the settings to use the Bluemix options.

    Add your device ID and click on the tick “All” on the other options.

    If the Bluemix options do not appear then double-check you have connected your IBM Cloud’s instance of Node-RED to IBM Watson.

    Then drag 2 function nodes Node-REDapp-watson-function-nodeand double click on each node and add the message below so that inputs and outputs can be read:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-read-inputs

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-read-outputs

    Finally, add a debug node  Node-REDapp-watson-debug-node and attach it to the function node.

    Below is IBM Cloud’s Node-RED flow:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-IBM-cloud-complete-flow

    If “Deploy” is clicked on both Node-RED instances you can see the BB-400’s IO status being sent from the BB-400’s Node-RED instance:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-bb-400-output

    and the IO status messages being received on IBM Cloud’s Node-RED instance:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-IBM-cloud-output

  9. Example 2: Sending data from IBM Cloud's Node-RED to your BB-400

    It is also possible to¬†send a message to adjust the IO lines from IBM Cloud’s Node-RED instance and receive it on¬†the BB-400.

    Start within the IBM Cloud’s Node-RED instance, drag an inject node¬† Node-REDapp-watson-inject-node¬†and configure the node as follows:

    how-do-i-connect-bb-400-to-ibm-watson-using-node-red-adjust-io-lines

    The inject node has been configured to change alternate IO lines to 1, which turns the LEDs on the front of your BB-400 off.

    Now, you can send the message to the BB-400 using an ibmiot out node, Node-REDapp-watson-ibmiot-node-1  and change your settings to Bluemix.

    how-do-i-connect-bb-400-to-ibm-watson-using-node-red-ibmiot-send-message

    Click on “Deploy” and click the tab next to the inject node.

    The payload message is being sent from the IBM Cloud to your BB-400 and you should see a change in the IO status of your BB-400 so alternate LEDs are switched off.

    You can also check the change in IO status within the web admin IO status page:

    how-do-i-connect-bb-400-to-ibm-watson-using-node-red-io-status

  10. Example 3: Sending and receiving serial data from the BB-400 and IBM cloud

    Create a new flow and add an inject node Node-REDapp-watson-inject-nodeto your workspace.

    Configure the node as follows:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-inject-node-config

    Now add a random node, How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-random-node attach it to the inject node and configure it as follows:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-random-node-configuration

    Then add a serial output node How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-serial-output-nodeand attach it to the random node. The serial node can be configured using the settings below or settings of your own choosing:

     How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-serial-output-node-configuration

     

    Below the nodes listed above, drag a serial input node onto your workspace. Double click on the node to make sure its settings match those of the serial output node above. 

    Add an IoT Watson output node and connect it to your serial input node. Configure the node so that it uses the correct settings.

    Also add a debug node Node-REDapp-watson-debug-nodeand attach it to your serial input node so that you can see the serial data that is being sent to the cloud.

    Your workspace should look like below:

     

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-complete-serial-flow

    Next, navigate to your IBM Watson’s instance of Node-RED, add an IoT Watson input node and make sure the settings are correct. Attach a debug node¬†Node-REDapp-watson-debug-nodeto the IoT Watson input node.

    Click deploy on both of your instances of Node-RED.

    You should see messages being sent from your BB-400’s Node-RED:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-serial-data-sent

    and being received on your IBM Watson’s Node-RED:

    How-do-i-connect-the-bb-400-to-ibm-watson-using-node-red-serial-data-received

  11. Conclusion

    You have successfully connected your BB-400 to the IBM Cloud using Node-RED, sent IO and serial data from your device to the cloud, and the cloud has been able to receive the messages.

    You have also sent data from IBM cloud to toggle the IO lines on your BB-400. 

Join The Discussion