In this tutorial, we will be demonstrating connectivity to the AWS IoT platform (https://aws.amazon.com/iot/). 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.
MQTT Client (paste under Clients)
NTP Client (paste under Clients). This insures that your RediGate has the correct system time, which is important for the TLS certificates.
The ${GATEWAY} parameter in your MQTT Client's "Last Will Topic" references the System → Unit Name value. For this example, change the Unit Name to "RG-AWS".
Copy Table data from the Elecsys-AWS-Demo.xml Internal Channel 15 → Scan Table into your RediGate Configuration (in Internal Channel 15, open Scan Table, right-click and select Paste, over-write data).
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 most IoT platforms charge on a per message or KB basis. |
Edit your TLS Tunnels → STUNNEL Parameters object so that the "Connect To" field matches the end point in your AWS IoT system.
(In AWS IoT Platform, see "Settings" for the "Custom endpoint" name.)
Download all of the keys and the root CA to your computer.
Note: You will need to rename the certificate, private key, and root CA to match the name of the files specified in the TLS Tunnels object (cert.crt, privkey.key, ca.pem in the screenshot below). By default, Windows does not allow users to view/edit file name extensions, so you may have to change that setting under Control Panel → Folder Options: |
Click the "Activate" button to activate the certificate.
cd /home/director
mv cert.crt /etc/stunnel
mv ca.pem /etc/stunnel
mv privkey.key /etc/stunnel
/home/director
folder, check the /home/Dirupld
folder.reboot
Your RediGate will publish data every ~10 minutes since the scan rate value for "Internal Channel 15" is set to 600 seconds. If you would like to see data updated more quickly (the screenshot below has data updating every 10 seconds), you can lower that value and view the data being published in AWS using the "Test" tool
Select "Test", then "Subscribe to a topic".
Enter "RG/#" for the Subscribe topic, and click the "Subscribe to topic" button.
The data published from the RediGate should appear here whenever it is published, as shown below.
Once your RediGate is successfully publishing data to AWS, the next step is to subscribe to commands sent from AWS 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:
RG/RG-120C/Channel15_VirtualRW/CMD or RG/${GATEWAY NAME}/${CHANNEL NAME}_${DEVICE OR RTU NAME}/CMD
{"d": {"IntValue": 12345}}
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 publish data to and subscribe to data from the AWS IoT service with your RediGate. You are now ready to start connecting real field devices to AWS IoT. Check out our "Field Device Quick Starts" found at http://redigate.elecsyscorp.com/examples/ for examples showing how to connect the RediGate to 60+ industrial protocols. |