Paige Liu's Posts

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:

  1. Register a device in Azure IoTHub: Register a device
  2. 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: Generate SAS token
  3. 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.
  4. Set up Device Explorer to monitor messages from IoTHub as documented here.
  5. 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. Send message Monitor message