Issue with MQTT reconnecting to broker if wifi connection goes down

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

With 3.5.2. When connecting to a MQTT broker over wifi, if the network is disconnected the connection to the MQTT broker is not resumed when the network comes back up. I tried different things (bring everything down and back up, reuse the MQTT connection, etc) but I'm not sure the MQTT library handles the broken connection correctly.

Is there a newer version of the SDK I can try or an example on how to do this?

Thank you

0 Likes
8 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

Adding vik86​ and peter_fenn as one of them may know how to do this...

0 Likes
VikramR_26
Employee
Employee
25 sign-ins 10 sign-ins 10 comments on KBA

Make sure you deinit the mqtt and connect again. Its a good find , we can have this logic incorporated in our sample apps. Thnx for pointing it .

0 Likes
Anonymous
Not applicable

I'm pretty sure I tried that but there was an issue when trying to bring the connection back up. I'll try again. Thanks

0 Likes
Anonymous
Not applicable

same problem here. There is a no graceful way of deinit of MQTT and starting over again. Moreover, once you move the whole MQTT into an application thread, things get murkier, since now you have to join and delete the thread and then start the thread again.

All the snippets on MQTT assume that the end-application will have MQTT running in the main application ... which is not practical.

vik86 wrote:

Make sure you deinit the mqtt and connect again. Its a good find , we can have this logic incorporated in our sample apps. Thnx for pointing it .

Hi vik86​,

The follow up comments in this thread shows "deinit the mqtt and connect again" does not work.

Does it really work for you? Or any further comments?

Thanks.

0 Likes
Anonymous
Not applicable

No it does not work

0 Likes
Anonymous
Not applicable

Can you please provide example to "deinit and connect again" on MQTT disconnect. Without this, i can hardly imagine going into production.

0 Likes
Anonymous
Not applicable

Hi,

I think there was a major memory leak in the tls library, I did help for us.

U can try this link. every mqtt connection consume about 8k ram

in mqtt_network_deinit() /mqtt_network.c file/ -> missing wiced_tls_deinit_indentity()...

below fix:

wiced_result_t mqtt_network_deinit( mqtt_socket_t *socket )

{

    wiced_tcp_unregister_callbacks( &socket->socket );

    mqtt_network_disconnect( socket );

    if ( socket->socket.tls_context != NULL )

    {

        wiced_tls_reset_context( socket->socket.tls_context );

        wiced_tls_deinit_identity( &socket->tls_identity ); // add this call

    }

    if ( socket->socket.tls_context != NULL )

    {

        wiced_tls_deinit_root_ca_certificates( );

    }

    wiced_tcp_delete_socket( &socket->socket );

    return WICED_SUCCESS;

}

Regards,

Nishal

0 Likes