5 years, 8 months ago.

MQTT permanent connection

How can I leave the connection always open waiting to receive a publication? Communication is lost after a few minutes. I do not know if there is a possibility that he will always listen, like other bookstores. Example of arduino pubsubclient. I played with yield but I do not get more than a couple of minutes. Thank you

Question relating to:

Deprecated This team is no longer maintained, please use: https://github.com/ARMmbed/mbed-mqtt instead.

2 Answers

5 years, 3 months ago.


I'm facing exactly the same issue using easyConnect and MQTT libraries. The connection get lost after some idle time. I need to keep the connection alive. Secondly, the method client.isConnected always return true even if it is not connected to the broker.

Please guide.

No, it's still the same, I have no solution. I have decided to work with the ESP32 platform and arduino. It works very well.

posted by Javier Dominguez Blanco 17 Aug 2018
5 years, 8 months ago.

The MQTT server to which you are connecting could have some information on its log as to why the connection was broken. This would be a good place to start, if you have access to the log. Or you could connect to a locally running server like Mosquitto if the log is inaccessible to you.

My guess is that it's a keep alive timeout. Keep alive is an MQTT mechanism for ensuring that the TCP stays connected, and detecting closed connections. A 'ping' message is sent by the client library at intervals specified by the keep alive interval, and it expects a response from the server. A simple way to verify this is to set the keep alive interval to 0, which turns off this mechanism, and see if the behaviour changes. If the connection stays active then you need to call yield() at sufficient intervals, depending on the keep alive interval used, to allow the 'ping' exchange to complete.

Sorry but I do not know where to change this: keep alive interval to 0. Thank you.

posted by Javier Dominguez Blanco 10 Apr 2018