Reconnection with Arduino client after MQTT restarted

Hi

We are using the Losant Arduino mqtt client library to connect to Losant.

When the Losant mqtt server was restarted after maintenance we detected the loss of connection and attempted to reestablish the connection by executing device.connectSecure(…)

This did not work.

What is the recommended way to clear a connection and restart it after the connection fails?

Many thanks,

John

Here’s some sample code with reconnect logic that we’ve been using in workshops for quite some time. Please check it out and see if there’s anything in this that might be helpful:

Hi Brandon

Many thanks - as I read this, if the link goes down (ie if(!device.connected())) then you restart the connection by executing device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET); - you do nothing else to clear the failed connection.

We do exactly this, but when the Losant server was restarted after maintenance the link did not restart.

I will investigate further to see if I can reproduce the error in a more repeatable way.

Best Regards,

John

1 Like