Closed koffienl closed 6 years ago
Thank you for sharing your findings.
@koffienl Please see this commit e15b7a82, is this ok?
@omersiar I adopted your changes for setting the char *mhs
and int
global and setting the values on the startup. Replaced my hardcoded setserver with mqttClient.setServer(mhs, mport);
just before calling mqttReconnectTimer.once(60, connectToMqtt);
Works as expected. It does a reconnect properly. Thanks :)
Tested with 0.8.0 , but looking at the 0.8.1 code I think it will be the same. When the mqtt server is down or for whatever reason the mqtt connection is lost, there will be a line in the eventlog:
Disconnected from MQTT server | TCP_DISCONNECTED
but reconnect never works.I added some debug writes to the eventlog to see where it fails, but I can't find the issue. After discovering the disconnect a reconnect is scheduled for after 60 seconds. The attempt is made, but the connect is never arrived at the mqtt server, resulting in a loop to try to reconnect. Looking at some issues of the used AsyncMqttClient lib, I'm feeling the issue might be in the lib?
To summarize:
UPDATE : After a tonload of testing, debugging and pulling my hair out, I managed to have a reconnect! In the
onMqttDisconnect
function I added setting (again) the server to connect to, right before calling the ticker:mqttClient.setServer("192.168.2.6", 1883);
It seems that somehow magically the library forgets it's server connection (but remembers the user / pass). Easiest solution would be the re-read the json and set the server from the config, or on booting up push the server settings in global variables and use it in the onMqttDisconnect.
For now I have a quick dirty ptach by simply hardcoding the broker address.