Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT reconnect fails after Wifi-disconnect #736

Open
dobernhardt opened this issue Oct 26, 2022 · 10 comments
Open

MQTT reconnect fails after Wifi-disconnect #736

dobernhardt opened this issue Oct 26, 2022 · 10 comments

Comments

@dobernhardt
Copy link

dobernhardt commented Oct 26, 2022

When rebooting the Wifi-AP or temporarily shutting down Wifi for any other reason the device does not reconnect to the MQTT broker but gets stuck in an endless reconnection loop

✔ Wi-Fi connected, IP: 192.168.100.90
Triggering WIFI_CONNECTED event...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...
↕ Attempting to connect to MQTT...

If only the connection to the MQTT broker is lost a reconnect works without any problems.

I'm using latest e0347c0 from develop on an esp32 (M5StickPlus).

@dobernhardt
Copy link
Author

Probably related to #320 ?

@dobernhardt
Copy link
Author

Solved it with the workaround

void onHomieEvent(HomieEvent event) {
  switch(event.type) {
    case HomieEventType::WIFI_DISCONNECTED:
        Logger::log(LogLevel::LOG_WARN,"Got Wifi Disconnected event") ;
        ESP.restart() ;
        break ;
  }
}

@luebbe
Copy link
Collaborator

luebbe commented Nov 2, 2022

OK, that's the sledgehammer method :)
The develop branch is the most up to date and works fine for me, but I'm only using esp8266, so I can't say if it is ok for ESP32.

@Pierre-33
Copy link

Pierre-33 commented May 21, 2023

Hi,
I'm having exactly the same issue with e0347c0 on an esp8266.

After some test, it appears that it's because I use AsyncMqttClient 0.9.0 instead of the 0.8.2 packaged with Homie. Was that your case as well?

Unfortunately my home assistant auto discovery payload seems too big for 0.8.2, so I really need to stick to 0.9.0

@dobernhardt
Copy link
Author

I was indeed using the version 0.9.0 of the AsyncMqttClient library. I have not tested with an older version and I'm still relying on my sledgehammer workaround resetting the device on WIFI_DISCONNECTED.

@luebbe
Copy link
Collaborator

luebbe commented May 22, 2023

@bertmelis has developed a much more stable mqtt library (https://github.com/bertmelis/espMqttClient). It is long on my todo list to replace asyncmqtt with bert's library in homie.

@Pierre-33
Copy link

I was indeed using the version 0.9.0 of the AsyncMqttClient library. I have not tested with an older version and I'm still relying on my sledgehammer workaround resetting the device on WIFI_DISCONNECTED.

I use the same kind of tricks but on the WIFI_CONNECTED event as doing the reboot in the WIFI_DISCONNECTED event somehow made the esp reboot again and again untill the Wifi is back.

@Pierre-33
Copy link

@bertmelis has developed a much more stable mqtt library (https://github.com/bertmelis/espMqttClient). It is long on my todo list to replace asyncmqtt with bert's library in homie.

That sounds like a lot of works. I was under the impression that Homie development has kind of stopped. I was looking for a tiny synchronous MQTT Client that I could use to publish my HomeAssistant Autodiscovery message when the esp boot and then shut it down and let Homie works with 0.8.2. But all I could find it "huge" async mqtt client that requires an update loop and I didn't feel like having two Mqtt client working in parallel even if it's just during setup.

@bertmelis
Copy link
Contributor

Wel actually, you only need Homie.

Let Homie do the work and use its mqtt client to send the discovery messages: Homie.getMqttClient().

@Pierre-33
Copy link

Pierre-33 commented May 22, 2023

yes, that's what I do, but Homie Mqtt Client doesn't support "big" payload (my payload are actually quite small). That's why I upgrade it to 0.9 in the first place. And now I got this reconnection issue. So I was looking for a solution to rollback to AsyncMqttClient 0.8.2 and use another client for my "big" payload.

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

No branches or pull requests

4 participants