philbowles / h4plugins

Adds GPIO handling, WiFi, MQTT, Webserver to H4 timer/scheduler. Multi-Platform plugins adding everything needed to create your own multi-function IOT firmware.
46 stars 17 forks source link

Fix issue #7 (MQTT reconnection) #8

Closed HamzaHajeir closed 3 years ago

HamzaHajeir commented 4 years ago

Hi

Fix to #7 where this is the scenario : = Router reboots = MQTT senses disconnection, onDisconnect called :

Here I've managed to (delay) the re-connection So network event can occur before trying to reconnect to MQTT. https://github.com/HamzaHajeir/h4plugins/commit/3e0b6236c7f0287ed969fa2b95b705edbdf188a0

This pull request contains another commit that solves another problem :

The problem is : After MQTT is established again after a reboot, and after 30 seconds of unreachable MQTT server : onDisconnect is called, in which it doesn't activate the reconnection lines because _discoDone = true.

That's because It doesn't pass through onConnect() callback function that sets _discoDone to false.

Removing _discoDone codes in H4P_AsyncMQTT solves the issue. And MQTT reconnects all the time without any issue.

Hope it helps

Hamza Hajeir

HamzaHajeir commented 4 years ago

Found bugs at this state, Closing until it's fixed.

HamzaHajeir commented 4 years ago

Hi

I've fixed and tested the code in my environment.

All nodes are responding well between router reboots and after long-time missing broker (on My PC OFF).