Skip to end of metadata
Go to start of metadata

Introduction

In this tutorial, we will be demonstrating connectivity to Microsoft's Azure IoT Hub platform (https://azure.microsoft.com/en-us/services/iot-hub/). We will use a RediGate 120e with internet connectivity to demonstrate this connectivity, but this tutorial can be applied to any RediGate device with internet connectivity.

Example 1 : Publishing Simulated Data to Azure IoT Hub

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. Azure IoT Hub account (https://azure.microsoft.com/en-us/services/iot-hub/). In this example, you will obtain from Azure:
    → Azure IoT Hub account / Hostname
    → Device ID of the registered device
    → SAS Token
  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-AzureIoT-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-AzureIoT-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)


    6. Global Text (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. In the Internal Channel 15 of the Elecsys-AzureIoT-Demo configuration, open the Scan Table. Right-click and select Copy Table.
    In your configuration, open the Scan Table in Internal Channel.
    Right-click and select "Paste Table (over-write data)."


     

    Scan Table Info

    The "Scan Table" object tells the RediGate which RTU (Unit 2, the data simulator) to run at an interval (Scan Period) which is set to every 600 seconds. This is how frequently the RediGate will check the data simulator for changes, which will result in data being published every 10 minutes. You can change this to whatever number you would like, however you will want to keep an eye on the number of messages published as Azure charges on a per message basis.

  7. Update your configuration properties to match the parameters in your Azure IoT Hub account, as described in the following steps:
    1. In the Azure IoT Hub Device Explorer, create or obtain the information for your site's Hostname and Device ID.



      In the screenshot below, the Device ID (e.g. "RediGate120E") will be used as the Unit Name in your configuration.

    2. In the "System" object at the top of the configuration, change your "Unit Name" property to match the "Device Id" of the registered device in the Azure IoT Hub.
    3. Set your "MQTT_Client → User Name" property to match the "Hostname" property in Azure IoT Hub, followed by / and the Device ID at the end of the URL (in this example   /${GATEWAY}   since that is what we are using for our Device ID), such as:
      elecsysdev.azure-devices.net/${GATEWAY}


      The ${GATEWAY} parameter in MQTT Client properties is used as a variable to reference the System → Unit Name property.

  8. Update the "TLS Tunnels → STUNNEL Parameters" property to match the "Hostname" property of your Azure IoT hub, followed by   :8883   such as:
    elecsysdev.azure-devices.net:8883



  9. Use the Azure "Device Explorer Twin" software tool (https://github.com/Azure/azure-iot-sdks/releases/download/2016-11-17/SetupDeviceExplorer.msi) to create a SharedAccessSignature
    1. Find the "Connection string – primary key" for the "iothubowner" user in Azure.


    2. Copy these credentials into the "Connection Information" section on the "Device Explorer Twin"


    3. Once you have a successful connection in the "Device Explorer Twin", navigate to the "Management" tab and select the appropriate Device ID, press the "SAS Token" button, set the appropriate TTL (days of validity for the device key), and click "Generate"


    4. Copy the highlighted section below from your SASTokenForm beginning after the ";SharedAccessSignature=". 


    5. Paste into the first row of the "Global Text" object of your RediGate configuration, in the "Replacement Text" column.
  10. Upload configuration to your RediGate
  11. Confirm that data is being published every 10 minutes using the "Device Explorer Twin" Data tab:

 

Example 2: Sending Data from Azure to Field Device

Once your device is successfully publishing data to Azure, the next step is to subscribe to commands sent from Azure 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:

  1. Open the Microsoft "Device Explorer Twin" software, and perform the following steps:
    1. Select the "Messages To Device Tab"
    2. Select your device from the "Device ID" dropdown, and copy the following text into the "Message" field:   {"d": {"IntValue": 150}}
    3. Enter "device" for the "Key" field and "VirtualRW_" for the "Value" field (make sure to include the underscore character _ after the VirtualRW).
    4. Click "Send" to send the command to the IoT Hub, which the RediGate will subscribe to and send out to the "IntValue" tag under VirtualRW RTU
  2. 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: 
  3. 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 subscribe to data from the Azure IoT Hub with your RediGate. You are now ready to start connecting real field devices to the Azure IoT Hub. 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 Azure subscription works, check out the Microsoft Azure IoT Hub Use Case Notes.

 

 

 

 

 

 

  • No labels