Here's my situation, I've got an Arduino MKR 1010 Wifi with an ENV Shield. The Arduino is using MQTT via the PubSubClient library to talk to Home Assistant and report the temp, humidity, and light intensity in the bathroom via WiFi. It tends to work for 24-48 hours before I need to reset the board. The symptom I see is that I stop getting updates to Home Assistant. If I look at my MQTT broker, it says that the arduino disconnected.
I wanted to figure out if this was happening because of a WiFi outage or a MQTT issue. So I attached a blue LED and green LED to pins 13 and 14. Here is the code: arduinomasterbath.ino · GitHub
What I expect to happen: The board should come up with both LEDs off. The WiFi LED (green) should come on first. (Not just because of the way I've written the code, but also because it doesn't make sense that the MQTT would connect until there's WiFi). Then the blue LED should turn on, signifying that MQTT is connected. After that, it should remain on until there's an outage. At that point either the green or the blue LED should be off, telling me where the issue is.
What I observe: The blue (MQTT) LED comes on first, then the green (WiFi) LED. When the disconnect happens, both lights are still on.
I don't understand why the LEDs stay on. Shoot, I don't even understand why the darn thing (as written) can't keep updating MQTT "forever" without needing a restart. There are checks throughout the code to reconnect to both MQTT and WiFi when they disconnect.
Some additional information: Took my Arduino for a walk by hooking it up to my laptop. What I learned makes my situation even more confounding to me.
- If I walk far enough to be out of WiFi range, the WiFi will disconnect and when I come back in range it will reconnect.
- The entire time I'm out of WiFi range, the Blue, MQTT, LED stays lit. HOWEVER, when I got back into WiFi, I saw "Attempting MQTT connection....connected". So it knew it was disconnected and needed a reconnection.