Supported Brokers¶
Push agent with the MQTT protocol supports the following Brokers:
Broker |
SSL |
NO SSL |
Mosquitto |
✓ |
✓ |
Azure IoT Hub |
✓ |
X |
Eclipse Mosquitto
Push agent supports the following modes of communication with a Mosquitto broker:
Anonymous: send and receive messages without authenticating with the broker;
Authenticated: send and receive messages once authenticated with username and password;
Secured: send and receive encrypted messages through SSL.
Once configured the broker for the desired mode, it is possibile to send messages. Port 1883 is only used for an anonymous/authenticated communication, however, port 8883 is used for a secured communication. Generally, the configuration of the broker can be adapted to your needs. In the configuration it is possibile to select the mode of communication and the port.
IoT Hub
Push agent for Iot Hub support only a secured mode. This consists of a client authentication through a SAS Token that is generated for each device that wants to send/receive messages from IoT Hub. The client authenticates using username and password, where:
username: e.g.
contoso.azure-devices.net/MyDevice01/?api-version=2018-06-30
password: e.g.
SharedAccessSignature sig={signature-string}&se={expiry}&sr={URL-encoded-resourceURI}
To generate a SAS Token you need to access the Azure portal to obtain the «IoT Hub connection string» as seen at https://devblogs.microsoft.com/iotdev/understand-different-connection-strings-in-azure-iot-hub/. After obtaining the «connection string», it is possibile to generate the token using two applications:
Device Explorer:
Download Device explore from https://github.com/Azure/azure-iot-sdk-csharp/releases
Install, run and insert the «IoT Hub connection string» in the relative field; press the «Update» button and go to the Management tab
Create a device by clicking «Create» if a device has not been already created.
Click the «SAS Token…» button
Select the desired device ( if not already selected)
Set the TTL (Days) to the number of days of the token’s validity
Click on the «Generate» button
Azure IoT Explorer:
Download Azure IoT Explorer from https://github.com/Azure/azure-iot-explorer/releases
Install and run it and insert «IoT Hub connection string» in the suggested field and press «Connnect»
Create a device by clicking “New” if a device has not been already created.
Select the desired device
Expand the «Connection string with SAS token» tab
Select «Primary Key» as Symmetric key
Set Expiration (minutes) to the token’s validity time in minutes
Click on the «Generate» button
Use the generated token as illustrated above to comunicate with the broker.
For each client that wants to send/receive messages, a device must be created on IoT Hub. It is not possible for clients to use the same devices to send/receive data. In contrast of Mosquitto IoT Hub is not a generic broker so it does not allow the option to send and receive information on custom topics. In fact, a device can send/receive information only on specific topics of the device, these are:
send:
devices/{deviceid}/messages/event/
receive:
devices/{deviceid}/messages/devicebound/#
To verify sending and receiving messages, Device Explorer and Azure IoT Explorer offer the possibility of monitoring received messages and sending messages to the device.