Domochip / WPalaControl

D1Mini to replace Palazzetti, Jotul, TurboFonte, Godin stove ConnectionBox
42 stars 9 forks source link

MQTT fail after power outage #38

Closed SlackPhoby closed 1 month ago

SlackPhoby commented 4 months ago

Hi, Thank you for this great work! Sorry for my English. I am reporting a bug that occurs after a power outage. The MQTT connection is lost, and 4 out of 6 chips on the same network fail to reconnect. The other 2 chips reconnect successfully. The failing chips require a manual restart to function again. I have 5 of them connected to the OpenHab MQTT broker. Three of them fail after a power outage, and 1 connected to Home Assistant fails too. The problem started after upgrading the firmware to 2.1.4. Before that, I was using version 1.4.1, and it worked well. Thanks again for your work. Sincerely, Axel I hope this is helpful!

Domochip commented 4 months ago

Hi, Thanks for your feeback. Could you let me know which exact version is currently on your module?

SlackPhoby commented 4 months ago

Hi, Currently I have version 2.1.5/3.1.2 (pre-release) on 2 devices, and these 2 devices fail to connect to MQTT after a power outage. On the other 4 devices, I have version 2.1.4/3.0.2 (latest), and 2 out of those 4 devices fail in the same way; the other 2 connect normally after a power outage. Before that, all devices were on version v1.4.1-2.1.1, and all of them connected perfectly after a power outage.

Domochip commented 4 months ago

ok,

For confirmation, you have 5 WPalaControl (and so 5 stoves) on the same Wifi network? When you got the issue, modules were reconnected to the Wifi and only the MQTT was disconnected? Did you got any other issue or instability? Could you let me know what is your MQTT configuration in one of your WPalaControl module? Does all module are configured the same way?

thanks

SlackPhoby commented 4 months ago

Hi, Yes, I have 6 stoves, each with its own wirelespalacontrol device, all on the same network (it's a tourist complex with cabins). I have a single Raspberry Pi with openHAB functioning as an MQTT broker. After a power outage, all of them connect well to the WiFi, but not all connect to the MQTT. All the devices have the same configuration. I think the problem is that the WiFi network comes up faster than the Raspberry Pi with openHAB starts, so they try to connect to an MQTT broker that hasn't started yet, but then they don't try again; they simply remain disconnected. For them to connect, I have to do a manual restart, and then they connect fine.

The strange thing is that before updating the version, it worked well, so I don't think it's a network or device configuration issue since the only thing I changed was updating the firmware. The configuration is exactly the same as it was with version 1.4.1.

Once connected, the devices work perfectly, with no instability or any other issues.

The MQTT configuration is as follows:

Type: MQTT
Upload period: 60
Hostname: [ipbroker]
Port: [1883]
No username
No password
Base topic: $model$
MQTT type: generic

Domochip commented 3 months ago

Hi, Sadly, I was not able to repeat the problem on my side. But I can see only one place where the problem can occur in the code. In my MQTT Management library, if the MQTT client is not connected, it will always retry to connect, except if a disconnection has been called. https://github.com/Domochip/WirelessPalaControl/blob/04ef6ba220e5e0dfc10867c8054c544e4dda59ee/src/base/MQTTMan.cpp#L133

WPalaControl do not disconnect MQTT except during a reboot but if MQTT is configured, a connection is executed just after. This means that PubSubClient (underlying library to connect to MQTT) should never return a state equals to MQTT_DISCONNECTED.

BUT there is a specific case which switch the state to MQTT_DISCONNECTED even if I don't call disconnection method, here : https://github.com/knolleary/pubsubclient/blob/2d228f2f862a95846c65a8518c79f48dfc8f188c/src/PubSubClient.cpp#L325

and then, I can find this issue which is mentionning this code : https://github.com/knolleary/pubsubclient/issues/927

I so have some new questions for you 😉 :

thanks for your help

SlackPhoby commented 3 months ago

Hi, yes of course, whatever you need! Currently, I have 5 stoves connected to Mosquitto MQTT v3 installed on a Raspberry Pi with OpenHAB 3.4. Out of these 5, 3 always fail (I live in a mountainous area with frequent snowfalls, so I have frequent power outages). The other stove is connected to Mosquitto MQTT v5 (latest version) installed on a Beelink mini PC with Home Assistant (also latest version), and it always fails after a power outage.

The failures occur only after a power outage. After a manual restart, they connect perfectly and do not fail. They work perfectly, with no connection errors or command loss, until the next power outage, when they fail again.

Attached is a photo of how the main tab looks after a power outage and another one after restarting and working properly. After power outage (missing mqtt state): Screenshot_20240701_162035_Chrome After reboot, working: Screenshot_20240701_162213_Chrome

Domochip commented 1 month ago

Hello, Ok, you are using Mosquitto as Broker but the version number you gave is not the Mosquitto version. For example, the latest on is 2.0.18 (https://mosquitto.org/download/) Could you check the version?

SlackPhoby commented 1 month ago

Hi, yes On a Raspberry Pi with OpenHAB 3.4

1

On a Beelink mini PC with Home Assistant

2

These are the versions I am currently using and in which this issue persists. thanks

Domochip commented 1 month ago

ok, I'll try to simulate wifi disconnection with a metal box and I can control an MQTT broker myself

Domochip commented 1 month ago

Thanks a lot for your patience, I was able to debug it and found the issue. The latest release fix the problem.