Skip to content
This repository has been archived by the owner on Jan 11, 2020. It is now read-only.

No Reconnect after MQTT Broker restart #62

Open
Nephelo opened this issue Jul 12, 2018 · 2 comments
Open

No Reconnect after MQTT Broker restart #62

Nephelo opened this issue Jul 12, 2018 · 2 comments

Comments

@Nephelo
Copy link

Nephelo commented Jul 12, 2018

Hello,

I have a problem that my Basecamp device doesn't automaticall reconnect to the MQTT Broker after the broker was restarted (e.g. after a server update).

Is there a possibility to configure Basecamp to automatically reconnect WiFi and MQTT after a connection lost?

Thank you very much.

@obrain17
Copy link
Contributor

Hi,

I also found out that polling the "MQTT Disconnect" too frequently is messing up the MQTT Library or TCP connection. Especially no attempts should be made to reconnect while the last reconnect actions have not completely finished.
I added a delay of 30 seconds here:
vTaskDelay(30000); // wait for all OnConnect Actions are completed
In addition we should wait some 2 seconds after a disconnect has been detected:
vTaskDelay(2000); // wait until try to connect ^= Timer 2 Seconds in example FullyFeatured-ESP32.ino

All in all polling the flag "mqtt->connected()", which is internally the variable "_connected" is not a good idea. It would be better to use a callback function "onMqttDisconnect" to trigger the reconnect, like it is done in the "FullyFeatured-ESP32.ino" example.
I will try and implement this and make a pull-request when I have it ready.

For the time being you might replace the function
void Basecamp::MqttHandling(void *mqttPointer)
in your "basecamp.cpp" with the one I attached. I intentionally put all original code only in comments, so you can see what I changed.

basecamp_mqtt.zip

If have made several tests, with MQTT broker (mosquitto) stopped and started, LAN connection unplugged, WLAN/WiFi disabled on Fritzbox …. and I always got re-connected afterwards.

@obrain17
Copy link
Contributor

See Pull Request #64

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants