Skip to end of metadata
Go to start of metadata

Introduction

In this tutorial, we will be demonstrating connectivity to IBM's Watson IoT platform (internetofthings.ibmcloud.com). We will use a RediGate 120e to demonstrate, but this tutorial can be applied to any RediGate device with internet connectivity.

Example 1 : Publishing Simulated Data to Watson IoT

Pre-Requisites

  1. A RediGate 100 or 400 series device with internet connectivity
  2. Completion of the Getting Started Guide for your respective RediGate device (RediGate 100 Series or RediGate 400 Series)
  3. IBM Watson IoT account (https://discover-iot.eu-gb.mybluemix.net)
  4. Ability to ping the Internet (using DNS, so an address like google.com) from your RediGate

Instructions

  1. Using ACE, Open the default configuration you used in the "Getting Started Guide".
  2. Download and open Elecsys-IBM-Demo.xml from the http://partner.elecsyscorp.com site within the same ACE window.
  3. In your default configuration, enable the DNS Client object by setting its Enabled checkbox.


  4. Disable Virtual Unit 3 by clearing its Enabled checkbox.


  5. Copy and paste the following objects from the Elecsys-IBM-Demo.xml config into your default configuration. 
    1. TLS Tunnels  (paste under Networks).


    2. FieldUnitInternalMast2 (paste under NullCircuit)


    3. VirtualRW Unit 4 (paste under NullCircuit)


    4. Data Simulator (paste under Internal Channel 15)



    5. MQTT_Client (paste under Clients)



    Renaming Copied Nodes

    Each node must have a unique name, so ACE automatically appends a timestamp to the name when it is pasted into a configuration. You can rename the nodes by clicking on the name of the node or by right-clicking on the node and selecting the "Rename Node" option (ACE 3.5 or later). The name has no operational significance and is user-definable – just make sure that the name remains unique in this configuration.



  6. Copy Table data from the Elecsys-IBM-Demo.xml Internal Channel 15 → Scan Table into your RediGate Configuration (in Internal Channel, open Scan Table, right-click and select Paste, over-write data). 
     

     



    Scan Table Info

    The "Scan Period" object tells the RediGate which RTU (Unit 2, labeled as FieldUnitInternalMast2) to run at an interval (Scan Period) which is set to every 30 seconds. This is how frequently the data will be published to Watson IoT.

    Warning: Data charges may result from excessive usage of Watson IoT service and/or cellular data plan.



  7. Update your MQClient3_1 → Client ID to match the parameters in your IBM account, as described below.


    1. Client ID: g:orgid:gatewaytype:gatewayid

      In this example, the orgid is 5bl949, gatewaytype is RG1.
      The gatewayid can be hard-coded, or use  ${SERIAL}  as a variable that substitutes for the RediGate serial number (40170-0118, in this example), or use  ${GATEWAY}  to substitute for the Unit Name in the System object.

      In the Watson IoT platform, you have to add a device with a gatewayid for the Device ID (serial number, unit name, etc.) that matches what will be published from the RediGate.


    2. Password: For the MQTT password, use the "Authentication Token" credentials created for your "Device" in Watson IoT.


  8. Under the "TLS Tunnels" object, update the STUNNEL Parameters to point to your IBM IoT app.

    The Connect To address should be:   orgid.messaging.internetofthings.ibmcloud.com:8883



  9.  Edit the JSON_RBE → Topic Rules object so that the table entries comply with the rules that IBM expects for your gateway type, device type, etc. See IBM Watson IoT Use Case Notes for more information about acceptable topic architectures.
    The following is given as an example in this configuration (change  gatewaytype  to match the Device type created in your IoT Platform):

    GATEWAY PUBLISH topic:      iot-2/type/gatewaytype/id/${SERIAL}/evt/STAT/fmt/json
    GATEWAY SUBSCRIPTION topic: iot-2/type/gatewaytype/id/${SERIAL}/cmd/SYS/fmt/json
    DEVICE PUBLISH topic:       iot-2/type/DEV/id/${SERIAL}_${DEV}/evt/RBE/fmt/json

    DEVICE SUBSCRIPTION topic:  iot-2/type/DEV/id/${SERIAL}_${DEV}/cmd/CMD/fmt/json



    NOTE: use one or the other graphic, not both.


  10. Upload configuration to the RediGate

  11. In the Devices section of Watson IoT, you should a gateway with a "Device ID" that matches the serial number of your RediGate, and two devices connected to the gateway named "(your serial number)_SimData" and "(your serial number)_VirtualRW":



  12. Click on the Gateway name to see the connection status.

  13. Data should be being sent from the SimData RTU every 30 seconds:


    Connection Not Establishing

    It may take up to 5 minutes after uploading the configuration to the Redigate for the connection to IBM to be established, especially over a cellular connection.

Example 2: Publishing Modbus RTU Data to Watson IoT

Once your RediGate is publishing simulated data to Watson IoT, you are ready to move on to publishing data from a field device that talks one of the 60+ protocols the RediGate supports.

Pre-Requisites

  1. Completion of "Example 1" above.
  2. Completion of the "Field Device Quick Start" corresponding to the field device you are trying to connect to. In this particular example, we will be connecting to an Open Modbus TCP device, but you should be able to connect to any of the field devices on our protocol list.

Instructions

  1. Confirm that you can ping the Modbus device using its built-in ping utility (See Ping Utility for more info)
  2. Open the configuration you used in the "Field Device Quick Start" in the same ACE window as your Watson IoT configuration that is producing the simulated data.
  3. Copy and paste the "Master Channel" object from the ModbusTCP configuration into your Watson IoT configuration (paste under "Master Channels").


  4. Save and upload configuration to the RediGate.
  5. If you followed the "Device Publish" topic structure in the "Publishing Simulated Data to Watson IoT" example above, you should see a new device named (your serial number)_(your unit name), which will be publishing data as it changes based on your channel scan rate:

 

Example 3: Sending Data from Watson IoT Node-RED to Field Device

Once your device is successfully publishing data to Watson IoT, the next step is to subscribe to commands sent from Watson to the field devices connected to the RediGate. Details on the JSON structure that the RediGate expects to receive can be found in the JSON-RBE MQTT Payload Format document. The steps below outline how to write data to an integer tag under a virtual field unit:

Pre-Requisites

  1. Completion of "Example 1" above.

Instructions

  1. Launch the Node-RED editor in Bluemix for your Watson IoT Platform (such as https://yoursitename.mybluemix.net/red – you may need to use Chrome or Firefox for this, not Internet Explorer).
  2. Add some logic to create a command message for the RediGate, as follows:
    1. In the Node- RED flow menu, select Import | Clipboard. Copy and paste the following into the node text:

      [{"id":"50b45600.8752c4","type":"inject","z":"d12d4d27.9ed49","name":"Trigger CMD","topic":"topic","payload":"{\"d\":{\"40001\":15}}","payloadType":"json","repeat":"","crontab":"","once":false,"x":170,"y":1800,"wires":[["87c66b13.34b61"]]},{"id":"87c66b13.34b61","type":"ibmiot out","z":"d12d4d27.9ed49","authentication":"boundService","apiKey":"","outputType":"cmd","deviceId":"deviceId","deviceType":"RG1","eventCommandType":"CMD","format":"json","data":"{}","qos":0,"name":"IBM IoT Command Output","service":"registered","x":410,"y":1800,"wires":[]}]



    2. The "Trigger CMD" inject node contains the JSON payload of the command. In this example we are using:
      IntValue: 15   (this is register 30001 in the example configuration)
    3. Modify the "IBM IoT Command Output" node to match the properties of the RediGate. In this example, we are using:
      Device Type: DEV
      Device Id: 40170-0118_VirtualRW       (this is a combination of RediGate serial, underscore, and virtual RTU name)
      Command Type: CMD


  3. After deploying changes in Node-RED, click the button on the "Trigger CMD" node to publish a command to the RediGate.


  4. Confirm that the data was written to the RediGate by logging in to the RediGate with Putty and accessing MQTT Client Diagnostic screen (Option 3 → 17). Here you should see a value in the "Last Recv Topic" that looks similar to the screenshot below:


  5. The value that you published should be saved in the Internal Channel 15 → Virtual RTU 4 → RTDB → Register 30001. See Accessing RTDB Data Dump for info on viewing RTDB values in the RediGate.

 

Congratulations! You can successfully published data to and subscribed to data from the IBM Watson IoT Platform with your RediGate. You are now ready to start connecting real field devices to Watson IoT. Check out our "Field Device Quick Starts" found at http://partner.elecsyscorp.com/examples/ for examples showing how to connect the RediGate to 60+ industrial protocols. For more in-depth detail about how the IBM subscription works, check out the IBM Watson IoT Use Case Notes