Azure IoT Hub (AMQP)
In this example, we configure an AMQP connection that publishes live messages as cloud-to-device (C2D) messages to Azure IoT Hub.
Prerequisites
To follow this example you will need:
- A Bosch IoT Things service subscription
- An Azure IoT Hub instance
- An Azure IoT Hub device
Create the connection
- Click Go to Dashboard in the row of your Things instance, which will manage the connection.
- On the Things dashboard open the tab Connections/Integrations.
- Click Create your first connection, or Add in case you have one already.
- Select AMQP 1.0 from the categories.
- Give the connection a name. Setting a name is required.
- Click the Continue button.
Configure credentials
- Scroll to the Coordinates section.
- Choose hmac as the credential type.
- Choose az-sasl as the algorithm.
- Click the button Paste Azure IoT Hub connection string.
Then paste the connection string of a shared access key with the service connect permission. - Enter the hostname of your Azure IoT Hub instance
<iot-hub-name>.azure-devices.net
The Time to Live field is the maximum duration a connection to IoT Hub stays open, before
it is closed by Azure and needs to reconnect. It is recommended to leave it empty, or configure a high value, e.g. 168h
(168 hours), to avoid frequent interruptions.
Add a target
- Scroll to the Targets section.
- Click the Add target button.
- Enter /messages/devicebound as target address.
- Add an authorization subject, e.g.
integration:<solution-id>:az
. - Check Thing live messages under Topics to publish on address.
- Add header mappings:
iothub-ack
⇾full
to
⇾/devices/{{thing:id}}/messages/devicebound
- Click Save new target.
- Click the Create button at the top right to save the connection.
The connection is ready. Any live message the connection is authorized to receive is published to Azure IoT Hub as Cloud-to-Device message.
Note that the thing ID of the live message should be equal to the device ID in Azure IoT Hub.
Authorize the connection for messages
Follow the steps “Create a Hello World thing” and “Add the authorization subject of the connection to the policy” on the Hub-to-Things connection tutorial to authorize the connection to receive live messages.
Remember to use the authorization subject of this connection in the policy, e.g. integration:<solution-id>:az
.