Overview

Skill Level: Any Skill Level

In this recipe, we will show you how to connect a specialized IoT gateway to the IBM cloud using MQTT.

Ingredients

Step-by-step

  1. IBM Cloud and Watson IoT platform

    The environment of IBM Cloud may look different because of possible changes. This guide shows the status of August 2019.

    IBM provides developers some free services for a limited time and you don’t have to enter any credit card details on the beginning. Create your IBM Cloud account and log into it on console.bluemix.net.

    To connect remotely to your IQRF network from the IBM cloud, you need to set up some services first.

  2. Internet of Things Platform Starter

    Click the Catalog button and find the Internet of Things Platform Starter.

    01-1

    02-1

    Fill in this form to set up your cloud application. Type in a unique App name, select your deployment location and your pricing plan and click Create button. Your web application will be available at the given address.

    03-1

     

  3. Watson IoT Platform

    Click the Dashboard in the left IBM Cloud navigation menu.

    04-1

    Click the Cloud Foundry Services item and then click the service which was created when you set up your cloud application in the previous step (it ends with iotf-service).

    05-1

    06-1

    Launch the IBM Watson IoT Platform.

    07-1

     

  4. Security

    Click the Security item in the left menu and check the connection security.

    08-1

    Set up the Security level according to your needs and possibilities. We have chosen the TLS Optional. Save the configuration.

    09-1

    10-1

  5. Create the Device Type

    Click the Devices item in the left menu.

    11-1

    First, add the Device Type.

    12-1

    It’s important to select the type: “Device”. Then, fill in the name of a device type.

    13-1

  6. Create the Device

    Click the Browse menu. Create a new virtual device by clicking on Add Device.

    14-1

    Select the Device Type which you have created in the previous step, enter the Device ID and click Next.

    15-1

    Fill in your Authentication Token and click Next.

    16-1

    Copy the device credentials. You will use them in the next step.

    17-1

  7. Set up the MQTT interface at the IQRF Gateway

    Configure the MQTT channel to the IBM Cloud. In the web browser on your computer, insert the IP address of your UP board, and log in to it as admin with password iqrf (or with the account you have created).

    In the IQRF Gateway web application, click on the IBM Cloud item in the Clouds menu.

    Fill in the credentials related to your virtual device from the IBM Cloud, save the configuration and restart the IQRF Gateway Daemon service (click Save and restart).

    2-1

  8. Node-RED

    Find your Cloud Foundry Application in the dashboard and check its status. It should be running. Then click it.

    3-1

    Next, click the link Visit App URL.

    3-2

    Go through the wizard and set up the Node-RED application. Go to your Node-RED flow editor and log in to it.

    3-3

  9. Node-RED flow

    Create a new flow and delete the example. You will do it by double-clicking the Flow 1 tab. Then press Delete.

    3-4

    Insert ibmiot input, ibmiot output, two debug outputs and inject input. Connect the objects like it is shown in the picture.

    3-5

    Using the inject input, we will send DPA commands to the MQTT broker running at the IBM Cloud and our IQRF Gateway will get commands from there. We will also send the commands to the debug window to see the output. All incoming messages from the MQTT broker will be displayed in the debug window.

  10. Modify the inject input

    Double-click the inject input, change the payload type to JSON and insert the DPA command in JSON format here.

    3-6

    Here is the command which turns ON the red LED on the IQRF coordinator. Click on Done.

    {“ctype”: “dpa”,”type”: “raw”,”msgid”: “1510754980”,”request”: “00.00.06.01.FF.FF”,”request_ts”: “”,”confirmation”: “”,”confirmation_ts”: “”,”response”: “”,”response_ts”: “”}

    3-7

    More examples:

    • Collecting all sensory data from Node #1 using the connected DDC-SE kit: 01.00.5E.01.FF.FF.FF.FF.FF.FF.
    • Turning ON both relays of DDC-RE kit connected to Node #2: 02.00.4B.00.FF.FF.03.00.00.00.01.01.
    • Acquiring temperature from Node #3: 03.00.0A.00.FF.FF.
    • For more information about macros and the IQRF network read the IoT Starter Kit – Part 1: Build your IQRF network.
  11. Modify the ibmiot output

    Click the ibmiot output. Change the authentication to Bluemix service, set the output type to Device Command, and fill in the information of the virtual device you have created earlier. Enter “iqrf” as the command type. Enter “msg.payload” as the Data and click Done.

    3-8

     

  12. Modify the ibmiot input

    Click the ibmiot input and select Bluemix Service as the authentication type. Save the configuration.

    3-9

  13. Test the connection

    Click the Deploy button.

    4-1

    Show the Debug tab.

    4-2

    Click the left corner of the Inject button. You send the prepared command to the MQTT broker and to the debug output as well.

    4-3

    In the Debug tab, you can see the ongoing communication between IBM Cloud and the IQRF Gateway. You can easily double-check that the command has been executed.

    4-4

    4-5

    In the same way, you can turn the red LED off as well as send any other DPA command to your network.

     

    The bidirectional communication between IQRF network and the IBM Cloud is up and running. Now it’s just up to you to use it for your own IoT solution.

Join The Discussion