This ROS package works with the Microsoft Azure IoT Hub service to relay telemetry messages from the Robot to Azure IoT Hub or reflect properties from the Digital Twin to the robot using dynamic reconfigure.
To use this ROS node on your Robot, you will need:
* Azure IoT Hub service and at least one device registered under IoT Hub.
* See more on [Quickstart: Send telemetry from a device to an IoT hub and read the telemetry from the hub with a back-end application](https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-c).
* ROS installation.
* For Windows environment, check [ROS on Windows](https://aka.ms/ros).
Azure IoT Hub maintains a device twin for each device that you connect to IoT Hub. Device twins are JSON documents that store device state information including metadata, configurations, and conditions.
We are using desired properties as a channel to ask our ROS node what ROS topics to report. The messages received from these ROS topics can either be reported through the telemetry channel or through the reported property channel on the device twin. The telemetry channel is designed for high bandwidth data and the history of messages sent over this channel are stored. The reported property channel is designed for low bandwidth data and it advertises only the latest message for each topic the device twin subscribes to.
Add the `ros_relays` block to the device twin. Use the client side deployment step to connect to your device. You can run the following Azure PowerShell cmdlet to wait for events from IoT Hub.
## Step by step tutorial: Viewing messages through the reported properties channel
### Step 1:
Create a new device twin on the Azure Portal and copy the connection string.
![create device][create_device]
### Step 2:
Populate the device twin with the desired properties tag, adding in the topics you want to subscribe to and the method with which you wish to receive the published messages. In this example, we are subscribing to the /hello topic and we will receive the messages through the reported properties channel.
![desired properties][desired_properties]
### Step 4:
Locally, deploy any ROS nodes you wish. As an example we will be publishing to the topic /hello as the device twin will be subscribing to it.
![publish topic][publish_topic]
### Step 5:
Launch the Azure Iot Hub ROS node and provide the connection string you just copied.
![launch node][launch_node]
### Step 6:
Back in the Azure portal your device twin should be updated with the latest published messages for each topic it is subscribed to.
[Dynamic Reconfiguration](http://wiki.ros.org/dynamic_reconfigure) provides a way to change the node parameters during runtime without restarting the node.
Similar as the telemetry reporting, we are using the device twin `desired` properties as a channel to ask our ROS node what dynamic parameters to reconfigure.
This value can also be set in the ROS Parameter Server at `/roscpp_azure_iothub_node/connection_string`.
Now you can run some other ROS scenarios and see the `/rosout` being reported back to IoT Hub or the node parameters being dynamically reconfigured.
# X.509 Certificate Authentication
By default, the ROS node will use SAS (Shared Access Signatures) to communicate with IoT Hub. Follow the instructions below to use X.509 certificates instead.
First, [set up X.509 security in your Azure IoT hub](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-security-x509-get-started#authenticate-your-x509-device-with-the-x509-certificates). Complete the steps until you reach "Authenticate your X.509 device with the X.509 certificates". Instead, the ROS node will be used to connect using the X.509 certificates.
After successfully creating, generating or puchasing the X.509 certificates, you should have a public key/certificate and a private key. If the keys were created for test purposes using these instructions, they should be stored in two files:`myDevice-private.pem` and `myDevice-public.pem`
Set the DEVICE_PRIVATE_KEY and DEVICE_PUBLIC_KEY environment variables to the full file name for the X.509 keys. For example, on Windows run (replacing 'myCertPath/myDevice' with the path and file name):
```Batchfile
set DEVICE_PRIVATE_KEY="C:/myCertPath/myDevice-private.pem"
set DEVICE_PUBLIC_KEY="C:/myCertPath/myDevice-public.pem"
```
To deploy, run the following. (replacing the value for `connection_string` with the value given by Azure IoT Hub)
```
::Launch the node using the X.509 sample launch file