Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Paho Mqtt C Client Error with MQTTAsync_connect if ssl cert files are missing

Hi

I am using Paho Mqtt C client for my application on imx6 platform.I  am facing issues with the SDK on imx6 platform while connecting to the server for below two cases:

Case1:
I started my application on the imx6 board and there is no internet as well as certificate files required for an ssl connection.In this case when i try to connect using MQTTAsync_connect function i get below errors:

In this case my application is getting killed sometimes or stops trying to connect after trying 5-10 times with below errors.These prints stops comming after sometime even if my application is running:

Debug: Connect failed, rc -1                                                                      
1982346336:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:393:                       
1982346336:error:140DC002:SSL routines:SSL_CTX_use_certificate_chain_file:system lib:ssl_rsa.c:682:utines:FILE_CTRL:system lib:bss_file.c:393: 1982346336:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:393:                       
1982346336:error:140DC002:SSL routines:SSL_CTX_use_certificate_chain_file:system lib:ssl_rsa.c:682:

Case2:
My application is running and internet connection as well as certificates are lost on my board.In this case also i am facing above issue and getting same prints.


I am getting same prints when i run my application on linux system.But my application keeps trying to connect and as soon as i find certificates and mqtt connection i s established.

I am pasting my code below:

    MQTTAsync_setCallbacks(client, NULL, connlost, messageArrivedCb, NULL);

   conn_opts._onSuccess_ = onConnect;
   conn_opts._onFailure_ = onConnectFailure;


  // Connect to the MQTT Broker
    if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
    {   
        ERROR("Failed to start connect, return code %d\n", rc);
        exit(EXIT_FAILURE);
    }   



//Connection lost handler
void connlost(void *context, char *cause)
{
    int rc;

    DEBUG("Connection lost\n");
    DEBUG("Cause: %s\n", cause);

    DEBUG("Reconnecting\n");
    if(!client)
    {
        ERROR("NO HANDLE\n");
        exit(EXIT_FAILURE);
    }
    if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
    {
        ERROR("Failed to start connect, return code %d\n", rc);
        exitFlag = EXIT_FLAG_VAL;
    }
}


// Successfull connection Callback
void onConnect(void* context, MQTTAsync_successData* response)
{
    DEBUG("Successful connection\n");
    connectionStatus = CONNECTION_OK;
}


//Connection Failure Callback
void onConnectFailure(void* context, MQTTAsync_failureData* response)
{
    int8_t rc;
    MQTTAsync client = (MQTTAsync)context;
    DEBUG("Connect failed, rc %d\n", response ? response->code : 0);

    if(!client)
    {
        ERROR("NO Client HANDLE Found\n");
        exit(EXIT_FAILURE);
    }

    if(!versionInfoFlag) {
        if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS)
        {
            ERROR("Failed to start connect, return code %d\n", rc);
            exitFlag = EXIT_FLAG_VAL;
        }
        sleep(CONN_FAILURE_SLEEP);
    }
}


Can i get help on this issue?

Back to the top