Connect MQTT Client to Azure IoT Hub
You can connect to Azure IoTHub using a generic MQTT client for testing. I tried some online MQTT clients without success. But MQTTBox works perfectly.
Here’s what you need to do:
- Register a device in Azure IoTHub:
- Download Azure IoTHub Device Explorer and connect it to your IoTHub. Generate an access token for the device to connect to IoTHub. Copy everthing from
SharedAccessSignature=
as shown below: - Download MQTTBox, and set up connection to Azure IoTHub using websocket as shown below. Note that
- Host should be appeneded with
/$iothub/websocket
- Username should be in the format
{your_iothub_name}.azure-devices.net/{your_device_id}/api-version=2016-11-14
- Password should be the SAS token you copied from the previous step.
- Host should be appeneded with
- Set up Device Explorer to monitor messages from IoTHub as documented here.
- Send a message from MQTTBox, and observe it from Device Explorer. Note that the topic must be in the format
devices/{your_device_id}/messages/events/{your_property_name1}={value1}&{your_property_name2}={value2}...
. The properties you put in the topic can be used for IoTHub message routing described here.