MQTT to Azure IOT Hub
17. 10. 2 오후 2:33

I am trying to connect out XDK to Azure IoT Hub with no success. I have followed the MQTT example tutorial and was able to connect to the example broker.

Now Azure IoT Hub uses a secure connection with username and SAS password. I have tried to adapt the code to but am not able to connect. Can somebody help me out?  



0 (0 투표)
RE: MQTT to Azure IOT Hub
17. 10. 2 오후 4:54 as a reply to Rutger Huggen.

Hi Rutger, how are you?

Actually the IBM Watson IoT Platform needs also to specify username and password, this is MQTT compliant, but the current MQTT Bosch Demo uses a version which does not need to be authenticated.

I was able to connect my XDK using a authenticated MQTT session, with this modified code based on bosch DEMO:


Goto MQTT_Paho/source/mqttPahoClient.c, at line 204/205 you will see how to populate the MQTT structure with the user/passwd for MQTT session authenticated, the definition of:




Are located on MQTT_Paho/source/mqttConfig.h starting from line 56, in this file you will also find the WiFI and MQTT broker definitios to be populated according your environment.

Please let me know if this information was useful.




0 (0 투표)
RE: MQTT to Azure IOT Hub
17. 10. 2 오후 8:50 as a reply to Felipe Neves.

Thanks Felipe. The problem  is Azure IOT HUB is using SSL/TLS. I have created the code below based on an other thread. But I am unable to connect.... I got no responds after the message connection to ........


Who can help me?


**    COPYRIGHT (c) 2016        Bosch Connected Devices and Solutions GmbH
**    The use of this software is subject to the XDK SDK EULA
**    OBJECT NAME:    mqttClient.c
**    DESCRIPTION:    Source Code for the MQTT Paho Client
**    PURPOSE:        Initializes the Paho Client and sets up subscriptions,
**                    starts the task to pubish and receive data,
**                    initializes the timer to stream data,
**                    defines the callback function for subscibed topics
**    AUTHOR(S):        Bosch Connected Devices and Solutions GmbH (BCDS)
**    Revision History:
**    Date             Name        Company      Description
**  2016.Apr         crk        BCDS         Initial Release

/* system header files */
#include <stdint.h>

/* own header files */
#include "mqttPahoClient.h"
#include "mqttConfig.h"
#include "mqttSensor.h"

/*************** Step 1 ***************/
#include "socket.h"            // AdeMike

/* additional interface header files */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "PTD_portDriver_ph.h"
#include "PTD_portDriver_ih.h"
#include "WDG_watchdog_ih.h"

/* paho header files */
#include "MQTTConnect.h"

/* constant definitions ***************************************************** */

/*************** Step 6 ***************/
#define CA_FILE_NAME "ms.der"    // AdeMike
unsigned char CA_KEY [] = {
0x30, 0x82, 0x03, 0x77, 0x30, 0x82, 0x02, 0x5F, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x04, 0x02,
0x00, 0x00, 0xB9, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05,
0x05, 0x00, 0x30, 0x5A, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49,
0x45, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x09, 0x42, 0x61, 0x6C, 0x74,
0x69, 0x6D, 0x6F, 0x72, 0x65, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x0A,
0x43, 0x79, 0x62, 0x65, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03,
0x55, 0x04, 0x03, 0x13, 0x19, 0x42, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x6F, 0x72, 0x65, 0x20, 0x43,
0x79, 0x62, 0x65, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x30, 0x1E,
0x17, 0x0D, 0x30, 0x30, 0x30, 0x35, 0x31, 0x32, 0x31, 0x38, 0x34, 0x36, 0x30, 0x30, 0x5A, 0x17,
0x0D, 0x32, 0x35, 0x30, 0x35, 0x31, 0x32, 0x32, 0x33, 0x35, 0x39, 0x30, 0x30, 0x5A, 0x30, 0x5A,
0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x45, 0x31, 0x12, 0x30,
0x10, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x09, 0x42, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x6F, 0x72,
0x65, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x0A, 0x43, 0x79, 0x62, 0x65,
0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
0x19, 0x42, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x6F, 0x72, 0x65, 0x20, 0x43, 0x79, 0x62, 0x65, 0x72,
0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D,
0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xA3, 0x04, 0xBB, 0x22, 0xAB,
0x98, 0x3D, 0x57, 0xE8, 0x26, 0x72, 0x9A, 0xB5, 0x79, 0xD4, 0x29, 0xE2, 0xE1, 0xE8, 0x95, 0x80,
0xB1, 0xB0, 0xE3, 0x5B, 0x8E, 0x2B, 0x29, 0x9A, 0x64, 0xDF, 0xA1, 0x5D, 0xED, 0xB0, 0x09, 0x05,
0x6D, 0xDB, 0x28, 0x2E, 0xCE, 0x62, 0xA2, 0x62, 0xFE, 0xB4, 0x88, 0xDA, 0x12, 0xEB, 0x38, 0xEB,
0x21, 0x9D, 0xC0, 0x41, 0x2B, 0x01, 0x52, 0x7B, 0x88, 0x77, 0xD3, 0x1C, 0x8F, 0xC7, 0xBA, 0xB9,
0x88, 0xB5, 0x6A, 0x09, 0xE7, 0x73, 0xE8, 0x11, 0x40, 0xA7, 0xD1, 0xCC, 0xCA, 0x62, 0x8D, 0x2D,
0xE5, 0x8F, 0x0B, 0xA6, 0x50, 0xD2, 0xA8, 0x50, 0xC3, 0x28, 0xEA, 0xF5, 0xAB, 0x25, 0x87, 0x8A,
0x9A, 0x96, 0x1C, 0xA9, 0x67, 0xB8, 0x3F, 0x0C, 0xD5, 0xF7, 0xF9, 0x52, 0x13, 0x2F, 0xC2, 0x1B,
0xD5, 0x70, 0x70, 0xF0, 0x8F, 0xC0, 0x12, 0xCA, 0x06, 0xCB, 0x9A, 0xE1, 0xD9, 0xCA, 0x33, 0x7A,
0x77, 0xD6, 0xF8, 0xEC, 0xB9, 0xF1, 0x68, 0x44, 0x42, 0x48, 0x13, 0xD2, 0xC0, 0xC2, 0xA4, 0xAE,
0x5E, 0x60, 0xFE, 0xB6, 0xA6, 0x05, 0xFC, 0xB4, 0xDD, 0x07, 0x59, 0x02, 0xD4, 0x59, 0x18, 0x98,
0x63, 0xF5, 0xA5, 0x63, 0xE0, 0x90, 0x0C, 0x7D, 0x5D, 0xB2, 0x06, 0x7A, 0xF3, 0x85, 0xEA, 0xEB,
0xD4, 0x03, 0xAE, 0x5E, 0x84, 0x3E, 0x5F, 0xFF, 0x15, 0xED, 0x69, 0xBC, 0xF9, 0x39, 0x36, 0x72,
0x75, 0xCF, 0x77, 0x52, 0x4D, 0xF3, 0xC9, 0x90, 0x2C, 0xB9, 0x3D, 0xE5, 0xC9, 0x23, 0x53, 0x3F,
0x1F, 0x24, 0x98, 0x21, 0x5C, 0x07, 0x99, 0x29, 0xBD, 0xC6, 0x3A, 0xEC, 0xE7, 0x6E, 0x86, 0x3A,
0x6B, 0x97, 0x74, 0x63, 0x33, 0xBD, 0x68, 0x18, 0x31, 0xF0, 0x78, 0x8D, 0x76, 0xBF, 0xFC, 0x9E,
0x8E, 0x5D, 0x2A, 0x86, 0xA7, 0x4D, 0x90, 0xDC, 0x27, 0x1A, 0x39, 0x02, 0x03, 0x01, 0x00, 0x01,
0xA3, 0x45, 0x30, 0x43, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE5,
0x9D, 0x59, 0x30, 0x82, 0x47, 0x58, 0xCC, 0xAC, 0xFA, 0x08, 0x54, 0x36, 0x86, 0x7B, 0x3A, 0xB5,
0x04, 0x4D, 0xF0, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, 0x08, 0x30,
0x06, 0x01, 0x01, 0xFF, 0x02, 0x01, 0x03, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01,
0xFF, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x85, 0x0C, 0x5D, 0x8E, 0xE4,
0x6F, 0x51, 0x68, 0x42, 0x05, 0xA0, 0xDD, 0xBB, 0x4F, 0x27, 0x25, 0x84, 0x03, 0xBD, 0xF7, 0x64,
0xFD, 0x2D, 0xD7, 0x30, 0xE3, 0xA4, 0x10, 0x17, 0xEB, 0xDA, 0x29, 0x29, 0xB6, 0x79, 0x3F, 0x76,
0xF6, 0x19, 0x13, 0x23, 0xB8, 0x10, 0x0A, 0xF9, 0x58, 0xA4, 0xD4, 0x61, 0x70, 0xBD, 0x04, 0x61,
0x6A, 0x12, 0x8A, 0x17, 0xD5, 0x0A, 0xBD, 0xC5, 0xBC, 0x30, 0x7C, 0xD6, 0xE9, 0x0C, 0x25, 0x8D,
0x86, 0x40, 0x4F, 0xEC, 0xCC, 0xA3, 0x7E, 0x38, 0xC6, 0x37, 0x11, 0x4F, 0xED, 0xDD, 0x68, 0x31,
0x8E, 0x4C, 0xD2, 0xB3, 0x01, 0x74, 0xEE, 0xBE, 0x75, 0x5E, 0x07, 0x48, 0x1A, 0x7F, 0x70, 0xFF,
0x16, 0x5C, 0x84, 0xC0, 0x79, 0x85, 0xB8, 0x05, 0xFD, 0x7F, 0xBE, 0x65, 0x11, 0xA3, 0x0F, 0xC0,
0x02, 0xB4, 0xF8, 0x52, 0x37, 0x39, 0x04, 0xD5, 0xA9, 0x31, 0x7A, 0x18, 0xBF, 0xA0, 0x2A, 0xF4,
0x12, 0x99, 0xF7, 0xA3, 0x45, 0x82, 0xE3, 0x3C, 0x5E, 0xF5, 0x9D, 0x9E, 0xB5, 0xC8, 0x9E, 0x7C,
0x2E, 0xC8, 0xA4, 0x9E, 0x4E, 0x08, 0x14, 0x4B, 0x6D, 0xFD, 0x70, 0x6D, 0x6B, 0x1A, 0x63, 0xBD,
0x64, 0xE6, 0x1F, 0xB7, 0xCE, 0xF0, 0xF2, 0x9F, 0x2E, 0xBB, 0x1B, 0xB7, 0xF2, 0x50, 0x88, 0x73,
0x92, 0xC2, 0xE2, 0xE3, 0x16, 0x8D, 0x9A, 0x32, 0x02, 0xAB, 0x8E, 0x18, 0xDD, 0xE9, 0x10, 0x11,
0xEE, 0x7E, 0x35, 0xAB, 0x90, 0xAF, 0x3E, 0x30, 0x94, 0x7A, 0xD0, 0x33, 0x3D, 0xA7, 0x65, 0x0F,
0xF5, 0xFC, 0x8E, 0x9E, 0x62, 0xCF, 0x47, 0x44, 0x2C, 0x01, 0x5D, 0xBB, 0x1D, 0xB5, 0x32, 0xD2,
0x47, 0xD2, 0x38, 0x2E, 0xD0, 0xFE, 0x81, 0xDC, 0x32, 0x6A, 0x1E, 0xB5, 0xEE, 0x3C, 0xD5, 0xFC,
0xE7, 0x81, 0x1D, 0x19, 0xC3, 0x24, 0x42, 0xEA, 0x63, 0x39, 0xA9,
int CA_KEY_LEN = 891;

/* local variables ********************************************************** */
// Buffers
static unsigned char buf[CLIENT_BUFF_SIZE];
static unsigned char readbuf[CLIENT_BUFF_SIZE];

// Client Task/Timer Variables
static xTimerHandle     clientStreamTimerHandle      = POINTER_NULL;  // timer handle for data stream
static xTaskHandle      clientTaskHandler            = POINTER_NULL;  // task handle for MQTT Client
static uint8_t clientDataGetFlag = NUMBER_UINT8_ZERO;
static uint32_t clientMessageId = 0;

// Subscribe topics variables
char clientTopicRed[CLIENT_BUFF_SIZE];
char clientTopicOrange[CLIENT_BUFF_SIZE];
char clientTopicYellow[CLIENT_BUFF_SIZE];
char clientTopicDataGet[CLIENT_BUFF_SIZE];
char clientTopicDataStream[CLIENT_BUFF_SIZE];
const char *clientTopicRed_ptr = TOPIC_LED_RED;
const char *clientTopicOrange_ptr = TOPIC_LED_ORANGE;
const char *clientTopicYellow_ptr = TOPIC_LED_YELLOW;
const char *clientTopicDataGet_ptr = TOPIC_DATA_GET;
const char *clientTopicDataStream_ptr = TOPIC_DATA_STREAM;

/* global variables ********************************************************* */

/*************** Step 2 ***************/
/* Create a global variable of type SlSockSecureFiles_t, called certificates. */
SlSockSecureFiles_t certificates;    // AdeMike

// Network and Client Configuration
Network n;
Client c;

/* inline functions ********************************************************* */

/* local functions ********************************************************** */
static void clientRecv(MessageData* md);
static void clientTask(void *pvParameters);

 * @brief callback function for subriptions
 *        toggles LEDS or sets read data flag
 * @param[in] md - received message from the MQTT Broker
 * @return NONE
static void clientRecv(MessageData* md)
    /* Initialize Variables */
    MQTTMessage* message = md->message;

    if((strncmp(md->topicName->, clientTopicRed_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_RED, PTD_PIN_LED_RED);
    else if((strncmp(md->topicName->, clientTopicOrange_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
    else if((strncmp(md->topicName->, clientTopicYellow_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
    else if((strncmp(md->topicName->, clientTopicDataGet_ptr, md->topicName->lenstring.len) == 0)) {
        /* Immediately Stream the Sensor Data */
        clientDataGetFlag = (uint8_t) ENABLED;

    printf("Subscribed Topic, %.*s, Message Received: %.*s\r\n", md->topicName->lenstring.len, md->topicName->,
                                                               (int)message->payloadlen, (char*)message->payload);

 * @brief publish sensor data, get sensor data, or
 *        yield mqtt client to check subscriptions
 * @param[in] pvParameters UNUSED/PASSED THROUGH
 * @return NONE
static void clientTask(void *pvParameters)
    /* Initialize Variables */
    MQTTMessage msg;

    /* Forever Loop Necessary for freeRTOS Task */
        /* Publish Live Data Stream */
        if(sensorStreamBuffer.length > NUMBER_UINT32_ZERO)
   = clientMessageId++;
            msg.qos = 0;
            msg.payload =;
            msg.payloadlen = sensorStreamBuffer.length;
            MQTTPublish(&c, clientTopicDataStream_ptr, &msg);

            memset(, 0x00, SENSOR_DATA_BUF_SIZE);
            sensorStreamBuffer.length = NUMBER_UINT32_ZERO;
        else if(clientDataGetFlag) {
            clientDataGetFlag = DISABLED;
        else {
            MQTTYield(&c, CLIENT_YIELD_TIMEOUT);

/* global functions ********************************************************* */

 * @brief starts the data streaming timer
 * @return NONE
void clientStartTimer(void)
    /* Start the timers */
    xTimerStart(clientStreamTimerHandle, UINT32_MAX);
 * @brief stops the data streaming timer
 * @return NONE
void clientStopTimer(void)
    /* Stop the timers */
    xTimerStop(clientStreamTimerHandle, UINT32_MAX);

 * @brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks
 * @return NONE

// AdeMike from HTTPS

/*************** Step 5 ***************/
// Flash the Certificate BEFORE attempting to connect.
void flashCertificate()
{   // For the purpose of readability this code has no error handling.
    // The simplelink API provides return codes of the type _i32 that can be
    // checked for the value SL_RET_CODE_OK
    // The datetime is required for certificate validation:
    SlDateTime_t dateTime;
    dateTime.sl_tm_day =   (_u32)12;
    dateTime.sl_tm_mon =   (_u32)3;
    dateTime.sl_tm_year =  (_u32)2017;
    dateTime.sl_tm_hour =  (_u32)0;
    dateTime.sl_tm_min =   (_u32)0;
    dateTime.sl_tm_sec =   (_u32)0;
        (_u8 *)(&dateTime)
    // If a file with the same name already exists, call this first:
    // sl_FsDel((_u8*) CA_FILE_NAME, 0)
    // The file handle should not be 0 after a file was successfully created:
    _i32 fileHandle = 0;

    // AdeMike Keys
    /*************** Step 7 ***************/
    /****** For CA ******/
            (_u8*) CA_FILE_NAME,
                    4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
    _i32 writtenLen_CA = sl_FsWrite(fileHandle, 0, CA_KEY, CA_KEY_LEN);
    printf("Written Length for %s: %d\n\r", CA_FILE_NAME, (int) writtenLen_CA);
    sl_FsClose(fileHandle, NULL, NULL, 0);
    fileHandle = 0;

void clientInit(void)
    /* Initialize Variables */
    int rc = 0;

    /*************** Step 3 ***************/
    flashCertificate();        // AdeMike
    // ConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT);

    /*************** Step 4 ***************/
    TLSConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT, &certificates, SL_SO_SEC_METHOD_TLSV1_2, SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256, 0);    // AdeMike
    MQTTClient(&c, &n, 1000, buf, CLIENT_BUFF_SIZE, readbuf, CLIENT_BUFF_SIZE);

    /* Configure the MQTT Connection Data */
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.willFlag = 0;
    data.MQTTVersion = 4;
    data.clientID.cstring = MQTT_CLIENT_ID;
    data.keepAliveInterval = 100;
    data.cleansession = 1;
    data.username.cstring = MQTT_USERNAME;
    data.password.cstring = MQTT_PASSWORD;

    printf("Connecting to %s %d\r\n", MQTT_BROKER_NAME, MQTT_PORT);

    /* Connect to the MQTT Broker */
    rc = MQTTConnect(&c, &data);
    printf("Connecting code is %d\r\n", rc);

    /* Set Subscribe Topic Strings */
    memset(clientTopicRed, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicRed, TOPIC_LED_RED, (const char*) MQTT_CLIENT_ID);
    clientTopicRed_ptr = (char*) clientTopicRed;

    memset(clientTopicOrange, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicOrange, TOPIC_LED_ORANGE, (const char*) MQTT_CLIENT_ID);
    clientTopicOrange_ptr = (char*) clientTopicOrange;

    memset(clientTopicYellow, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicYellow, TOPIC_LED_YELLOW, (const char*) MQTT_CLIENT_ID);
    clientTopicYellow_ptr = (char*) clientTopicYellow;

    memset(clientTopicDataGet, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicDataGet, TOPIC_DATA_GET, (const char*) MQTT_CLIENT_ID);
    clientTopicDataGet_ptr = (char*) clientTopicDataGet;

    memset(clientTopicDataStream, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicDataStream, TOPIC_DATA_STREAM, (const char*) MQTT_CLIENT_ID);
    clientTopicDataStream_ptr = (char*) clientTopicDataStream;

    /* Subscribe to the Topics (set callback functions) */
    rc = MQTTSubscribe(&c, clientTopicRed_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicOrange_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicYellow_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicDataGet_ptr, QOS0, clientRecv);

    /* Create Live Data Stream Timer */
    clientStreamTimerHandle = xTimerCreate(
            (const char * const) "Data Stream",

    /* Create MQTT Client Task */
    rc = xTaskCreate(clientTask, (const char * const) "Mqtt Client App",
                            CLIENT_TASK_STACK_SIZE, NULL, CLIENT_TASK_PRIORITY, &clientTaskHandler);

    /* Error Occured Exit App */
    if(rc < 0)


 * @brief Disconnect from the MQTT Client
 * @return NONE
void clientDeinit(void)


0 (0 투표)
RE: MQTT to Azure IOT Hub
17. 10. 4 오전 11:52 as a reply to Rutger Huggen.

Hello Rudger,

I am glad to see that you were able to insert username and password into the MQTT connect struct with Felipe's hint. Additionally, I see that you used code from Michael Ng's thread, who tried to connect to an AWS Broker.

The problem is, you are using an intermediate step (and even the last steps did not seem to work yet). The variable certificates is not needed, You can remove its declaration and replace its usage with NULL in TLSConnectNetwork().

Instead, the socket that is used for connection, needs to recognize that there is a certificate. For this, go to the file source > paho > XDK > mqttXDK.c and replace the line

sl_SetSockOpt(n->my_socket, SL_SOL_SOCKET, SL_SO_SECURE_FILES, &certificates, sizeof(SlSockSecureFiles_t));


sl_SetSockOpt(n->my_socket, SL_SOL_SOCKET, SL_SO_SECURE_FILES_CA_FILE_NAME, "ms.der", strlen("ms.der"));

This will make sure that the certificate is actually used during the connection process.

In addition, in flashCertificate(), uncomment the line sl_FsDel((_u8*) CA_FILE_NAME, 0). Deleting the CA before flashing it again will do no harm and ensures that the file is not corrupted due to flashing multiple times. This is not the cause of your issue, but functions as a safety measure.

Please let me know if that was helpful and do not hesitate to ask if you have further questions.

Kind regards,

+1 (1 투표)
RE: MQTT to Azure IOT Hub
17. 10. 9 오전 7:26 as a reply to Franjo Stjepandic.

Thanks Franjo, I have changed the code and I receive a return code "0". Now I need to figure out why it's not connecting to Azure.

I will give it another try this week and I will update the thread when I have some more results.


0 (0 투표)
RE: MQTT to Azure IOT Hub
17. 10. 9 오후 3:33 as a reply to Rutger Huggen.

Hello Rutger,

glad to hear that you were able to adapt the code correctly, and I am looking forward to your progress.

Kind regards,

0 (0 투표)
RE: MQTT to Azure IOT Hub
17. 10. 9 오후 8:36 as a reply to Franjo Stjepandic.

Hi Franjo,

I still don't get a connction to Azure. In my build log I still have 40+ errors (see below). How do i get rid of those? The source does build and load but no connection?

Description    Resource    Path    Location    Type
Symbol 'FAILURE' could not be resolved    MQTTClient.c    /MQTT_Paho/source/paho    line 32    Semantic Error

Thanks Rutger


0 (0 투표)
RE: MQTT to Azure IOT Hub
17. 10. 10 오후 1:08 as a reply to Rutger Huggen.

Hello Rutger,

these kind of errors occur with this demo, because Workbench tries to find the symbol in the project but finds multiple definitions of it. This error does not stop the compiler from building the project correctly, since the compiler will only know one definition of the respective symbol.

The Workbench has a linker, which is responsible for getting the correct definitions for certain symbols. This is done in order to enable Workbench features such as “Open Declaration” and static checks before even building the project. It’s a convenience for the user, except in some cases, where multiple declarations are found.

So, this is not the reason why the XDK does not connect correctly, since the XDK at least attempts to connect.

I would ask you to provide me a connection log of the Azure IoT Hub (if some such log exists) and the console log of the XDK-Workbench after a connection attempt?

Kind regards,

0 (0 투표)