Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] [Paho Mqtt C Client]: Automatic Reconnect does't work Some times


Both the traces show

Debug: Connection lost
Debug: Cause: (null)
Debug: Reconnecting

which implies that the connection lost callback is being invoked.  If you are using automatic reconnect I wouldn't expect to see the connectFailure callback invoked (actually I think there's a bug looking at the code where I need to zero out the connect failure callback pointer once invoked once).

These traces don't tell me much.  Taking client library traces by setting MQTT_C_CLIENT_TRACE=ON should give more information.

Also, your settings.  A connect timeout of 3 seconds?  That seems unnecessarily very low.   In some circumstances, the TCP connect might take longer - you're at risk of aborting a successful connect.


On 21/07/2017 07:50, vikas sharma wrote:
Hi Ian,

I am using Paho Mqtt C Client on my device to send event some notifications.I am facing issues with the automatic reconnect functionality.It is not working sometimes[2 out 10 times] when i plug out the ethernet cable from my device.

I have attached two log files here for the successful and failure cases for your reference.For the successfull case ,u can see the below prints which confirms that it is retrying to connect.

Debug: Connect failed, rc 0 (connect failure callback prnts)

But for the Failure case these prints are not coming which means it is not retying and connect failed callback is not getting called.

Code Details:
    conn_opts.keepAliveInterval = 5;
    conn_opts.cleansession = 1;
    conn_opts.automaticReconnect = 1;
    conn_opts.connectTimeout = 3;
    conn_opts.minRetryInterval = 4;
    conn_opts._onSuccess_ = onConnect;
    conn_opts._onFailure_ = onConnectFailure;

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

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

Kindly help me with this issue.Let me know if we need to modify the conn_opts values.


paho-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Paho Project Lead; Committer on Mosquitto

Back to the top