Developer Portal Community

    Showing results for 
    Search instead for 
    Did you mean: 

    Using an XDK 110 to publish MQTT messages to an Azure IoT Hub

    New Poster

    Using an XDK 110 to publish MQTT messages to an Azure IoT Hub

    My main objective was to publish MQTT messages to an Azure IoT Hub.  After creating my hub and IoT Device with a self-signed certificate in the Azure portal, I began setting up the SendDataOverMQTT example.  I filled in the values in AppController.h (relevant values shown below).


    #define APP_MQTT_BROKER_HOST_PORT UINT16_C(8883)

    #define APP_MQTT_CLIENT_ID "xdk_device_1"

    #define APP_MQTT_TOPIC "devices/" APP_MQTT_CLIENT_ID "/messages/events/"

    However, that wasn't enough information to create a connection to an Azure IoT Hub.  In order to connect and publish using my certificate, I had to add some code to provide the username to the MQTT session as required by Azure (see the UserName changes in the referenced patch file) and add code to use my certificate and key.

    C:\XDK-Workbench\XDK\SDK\xdk110\Common\certs\Mosquitto\ServerCA.h contained a definition of SERVER_CA.  I modified this file by replacing the contents of SERVER_CA with my root certificate and by adding my client certificate as CLIENT_CERT and my key as CLIENT_KEY.  These macro values are referenced in the MbedTLSAdapter_Initialize() function (see the referenced patch file).

    With these changes, I was able to successfully publish MQTT messages to my Azure IoT Hub.

    * The patch file would be applied with the -p0 option in the C:\XDK-Workbench\XDK\SDK directory.

    Chad Elliott

    Tags (4)
    2 REPLIES 2
    Community Manager

    Re: Using an XDK 110 to publish MQTT messages to an Azure IoT Hub

    Hi ocielliottc!

    Thanks a lot for your question!

    Our experts will have a look and we will get back to you as soon as possible!

    Stay tuned!



    Tags (4)
    Long-established Member

    Re: Using an XDK 110 to publish MQTT messages to an Azure IoT Hub


    Glad to hear that your XDK device is successfully communicating with the Azure IoT hub.

    Team will study further regarding the username and password required for the Azure MQTT session and add it as part of MQTT session structure in future XDK workbench release.

    Tags (4)