-
Notifications
You must be signed in to change notification settings - Fork 69
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 client does not connect to MQTT broker after a TCP reconnection #47
Comments
Hello, But this module automatically reconnects to the MQTT broker after rebooting my router after about 2-5 minutes. It is not necessary to intervene manually. Maybe you can look at the code and install the same solution there? Many Thanks. |
Hey, Thanks for reporting this issue. |
I ran into this today (again, it happend several times now). I did not look at the code, yet, but for my own projects, I usually do a simple connectivity check (wifi and mqtt) every 10 seconds or so. The libraries provide functions for that. I then either call a "reconnect function" or (if the project does not work without a connection) a esp reset. |
Happend again today after wifi was down because of a router reboot. I thought I'd try a quick and dirty fix and add publisher.connect(); before yield() in the main loop. src/main.cpp: In function 'void loop()': |
The problem is that when the connection is lost, the captive portal is activated and IotWebConf (the library I use for WiFi and configuration management) does not reconnect. But this seems to be fixed with the current version of IotWebConf. I will release a new version of SMLReader in the next few days, which will include an update of IotWebConf. |
I have already released an upgraded version on https://github.com/mruettgers/SMLReader/tree/feature/update-iotwebconf, but haven't had the time to test it thoroughly yet. You can find a binary compiled with this changes attached, so feel free to test ;-) |
Hm. There still seems to be an issue with the PangolinMQTT library not working after a WiFi reconnect (even if I call the connect() method again). |
Sorry, I've been on vacation for a few days. Possibly you should also execute a disconnect() methode before connect() if it is still connected. However, the debug output should provide information in our error case. Thank you for your help. |
I already tried to use disconnect() during my tests and it didn't change anything. So I need to debug the third party libs a bit more. |
PangolinMQTT comes with some built-in diagnostics. /* #define PANGO_DEBUG 4 |
Going to the http config page and hitting "apply" (after filling out the ap and wifi passwords restores the mqtt connection. |
Sorry, I did not have the time to look at this issue again yet. But what you say makes sense as the ESP is being rebooted after changing the config. |
I have seen the same problem in my setup using the SMLReader release version. In my case the device successfully connected to wifi, but the mqtt client did not reconnect. I have noticed in the log of my router that the wifi reconnect took 70 seconds. 30 seconds is the default wifi timeout in IotWebCon v2, afterwards it jumps for 30 seconds into AP mode, before it starts to reconnect.
|
I have the same disconnect issue. Could you solve it by simply increasing the timeout? |
I have seen the unit survived now multiple disconnects >30 seconds. But yesterday I had the problem again: The WIFI was reconnected after 10 minutes. I have no idea why this module gets disconnected for 10 minutes, it is located close to the router ... By the way, I added `iotWebConf.setWifiConnectionTimeoutMs( 300000l ); Seems the issue is known in PangolinMQTT: philbowles/PangolinMQTT#40 |
Ok, good to know. Thanks for your investigation. ;) |
Is the "beta" version still worth a try, if the disconnected phase is not too long? My FritzBox and -Repeaters also tend to reconnect in random intervals, so SMLReader gets offline. |
I have replaced PangolinMQTT with https://github.com/marvinroger/async-mqtt-client/. I also added a reset API endpoint (http://IP/reset) that can be used to restart the ESP. |
I forgot to mention that the WiFi and MQTT configuration might need to be redone since I also updated IoTWebConf. |
Is there a way to read out the settings that were used to flash the actual version? |
Hello Martin and thank you for your effort. |
The web interface will show you the basic settings (except the passwords). But you can make a backup of your ESP with esptool: For 1M flash: For 4M flash: |
Hello Martin I adapted the source code (PlatformIO.ini and config.h), compiled it and flashed it into the SMLReader (ESPLesekopf-Project). The settings for the AP and MQTT broker are adopted as before.
|
Hey DiKaY1969
It looks like you have to change the GPIO pin of the reader to 14 (default is D2) for use with the ESPLesekopf, see https://github.com/esplesekopf/SMLReader/blob/develop/src/config.h#L17.
I just had a quick look at the code of IotWebConf and there does not seem to be an easy way to access the stored password easily. I'll come back to this issue sooner or later when I have more time. Michael ;-) |
Hi Michael, yes I had configured the GPIO pin to 14. But it still doesn't work :-( Thomas' original project, based on SMLReader 2.2.1, works perfectly except for the MQTT problem. Thanks anyway for your help. greeting |
Could you please provide a precompiled binary? Thanks in advance. |
I had the same issue multiple times with version 2.2.0. What is verry helpful for me is the new reset link. Stilzchen |
Feel free to test with this files. EDIT: interval is set to 30 (more than enough for me) |
I flashed D2 with LED. So far, it is connected, but it updates the current power (W) only every 31 seconds. Is this intentional? |
I'll release a new version including this fix and with the default values (configured for D2 and with data published in realtime) this evening. |
Cool, thanks! I have seen requests to change the publish rate. Maybe this could be added as an option. I prefer realtime updates because I display them on a screen and I also use that to switch and regulate heaters depending on PV power. |
Thanks. I just compiled a version on my own yesterday with an interval of 15 min (had to change the interval datatype to uint16 for that to work. I'm only interested in the kWh not the watts. :) |
Hello,
I would like to report a BUG in the MQTT client of the SML reader which means that, for example after restarting the router, no more MQTT data is received from the MQTT broker. The SML reader can be reached via TCP, but the MQTT client no longer establishes the connection to the broker properly after the WLAN reconnects.
A restart of the SMLReader leads to success
Suggestion, simply close the MQTT client after the WLAN reconnects and reconnect if this is not already done?
Thanks in advance.
The text was updated successfully, but these errors were encountered: