Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

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

    ocielliottc
    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_URL "hub-name.azure-devices.net"

    #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.

    download.ociweb.com/xdk/MQTT_to_Azure_IoT_Hub.patch

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

    Chad Elliott

    objectcomputing.com

    Tags (4)
    2 REPLIES 2
    Grocamora
    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!

    Thanks!

     

    Tags (4)
    Padmapriya
    Long-established Member

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

    Hello,

    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)
    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist