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 timeout #74
Comments
Glad it works usually! And I think it should reconnect automatically even in your situation. It reconnects here automatically even after a longer MQTT server timeout. As long as WiFi remains available, the ESP will try to reconnect to the MQTT server every 5 seconds; if that doesn't succeed within 150 seconds, the ESP will restart (=D0), after which it will continue its reconnection attempts every 5 seconds, and it will also restart every 150 seconds. So there is no maximum timeout. And even without WiFi, the portal that will initiate after an ESP restart will timeout after 180 seconds to enable a WiFi reconnection attempt. So I do not yet understand why it does not reconnect on your side. (and at this moment the maximum timeout (or reattempt time) can only be changed in the configuration header file but this requires recompilation). Can you log and check what the ESP reports over telnet during and after the MQTT server timeout? This may require restarting your telnet sessions several times as the telnet sessions end when the ESP restarts. Are you sure it does not connect, or does it connect but is it not publishing new MQTT info? |
@Arnold-n thanks for your explanation. and you are right: the mitt connection reconnects, just checked it after the last night. I can see some values publishing, but not all of them (eg the C- and S-values are no more published). I am wondering why in HA all sensors are unknown... even the still published ones (T-values). As already written, after a reboot everything works again without any extra configuration needed. vie telnet I can see only this messages:
anything I could do to see more? ;) |
Thanks for your fast feedback, I think 2 different issues are involved: But if the ESP restarted at least once during the MQTT server unavailability, both HA init messages and all C/S values should be retransmitted; are you sure your MQTT server is unavailable for more than 150 seconds? An quick solution would be to (add an option to) restart the ESP after each MQTT reconnect (similar to your D1 restart) or after a MQTT reconnect longer than a certain period (currently effectively already implemented as the 150s restart timer). Or the ESP should resend all HA sensor initialization messages and all data values after each MQTT reconnect. I am not sure it is the best solution to retransmit a lot of data after each MQTT reconnect as it will be a burden for less reliable networks (MQTT reconnects signal a server restart or a network problem). |
@Arnold-n I just checked the logs of my NAS in detail. You are again right: the Matt server ist only unavailable for about seconds. the HA instance is unavailable for some more seconds :)
so as far as I understand you, I need to restart the ESP manually (or via an automation in HA which sends the "D1" command via telnet), as long as the ESP doesn't send its init messages again after a mutt reconnect. I will try that as a workaround. Ist it possible to just send the init messages without all other data messages after reconnection? or maybe could I retain the init messages via the server? |
Indeed, and I can add it as an option for a next release. Based on this topic storing retained messages on the server over a restart is possible via the persistence option. Resending the init messages after a reconnect is possible but also a lot of data, so the data throttling after a restart is needed, can be done but takes a bit more work than just a restart. |
@Arnold-n ok I created a short python script as workaround:
in addition I created an automation in HA which calls that script triggers by the HA restart itself. Will see if it works as expected this night and give feedback :) anyway, it would be great if you implement a solution directly in the firmware ;) |
Just my 2 cents. If you are using mosquito, you can save retained messages to disk which make them available after reboot of mosquito. See https://mosquitto.org/man/mosquitto-conf-5.html autosave_on_changes. @Arnold-n, as an alternative, you could potentially listen to the birth message of home assistant on the mqtt, to send the ha sensor configuration again. |
@fuecy, thanks, listening to the birth message makes sense anyway, thanks for the suggestion! |
I meant to report this as well a few months back! Good to see some solutions presented |
just a short feedback: both methods work as a workaround. you could use a script for resetting the p1p2 module, or you could save retained messages on persistent storage with mosquitto. |
v0.9.41, just released, adds a few solutions: Thanks again for your feedback which triggered these changes. |
hey, i am using the module now for a few days. in general it works good :)
my problem: every night, i stop all my docker containers (including mqtt server container and ha docker container) for backup purposes. after the backup they are restartet. the duration for this is 10 to 15 minutes.
the p1p2serial module is not reconnecting at all, all sensors are "unknown" in ha. after the command "d1" via telnet, all is working fine again.
is there any reconnection implemented in the software? if yes: is the a maximum timeout? could this be configured in any way?
The text was updated successfully, but these errors were encountered: