Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Paho Mqtt C Client: Automatic reconnect issue when connection is lost.


I am using Paho Mqtt C Client on my IMX6 device.Providing below some details regarding my code.

MQTTAsync client;
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;

Default connection initializer value.
#define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 4, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60}

    conn_opts.keepAliveInterval = 5;
    conn_opts.cleansession = 1;
    conn_opts.automaticReconnect = 1;
    conn_opts._onSuccess_ = onConnect;
    conn_opts._onFailure_ = onConnectFailure;
    conn_opts.context = client;

void onConnect(void* context, MQTTAsync_successData* response)
    printf("Successful connection\n");
    connectionStatus = CONNECTION_OK;

void onConnectFailure(void* context, MQTTAsync_failureData* response)
    printf("Connect failed, rc %d\n", response ? response->code : 0);

1. The issue i am facing with the sdk is that i am not able to see the prints of onConnectFailure callback sometimes.Although it works fine and i can see the logs most of the time.(2 out of 10 times)
Second issue is i am not able to see onConnect callback prints.If onConnectFailure prints are coming sometimes,same shall be the case with onConnect callback.
What is the exact meaning of connectTimeout value in default initializer.What shall be its value if the keepalive timeout is 5 secs.?

Back to the top