Closed ilshm closed 2 months ago
So if you do the same thing, but skip step 4, it connects fine?
So if you do the same thing, but skip step 4, it connects fine?
True
Are you calling MQTT.reconnect()
?
Are you calling
MQTT.reconnect()
?
Yes, if I don't call it everything is the same, after WiFi reset - works, if during the outage no messages arrive.
So that's probably the issue, since the socket was never flagged as disconnected. Can you try something for me? before you call reconnect()
, can you call _close_socket()
? This should fully disconnect the socket so it can be reused
Wanted to follow-up and see if that fixed it. If so we can figure out the right way to do this
Sorry for the delayed response. After experimenting with it, I found that the solution is either to call _close_socket()
manually or to modify the reconnect()
function to include this call. Thanks!
I'm using a Raspberry Pi Pico W with an MQTT client to connect to Adafruit IO. The Pico W handles WiFi reconnection well when the connection drops. However, there's an issue when messages are sent to the subscribed topic while the Pico W is disconnected from WiFi. After reconnecting to WiFi:
Important Note: If no messages are sent to the topic while the Pico W is offline, everything works as expected. The Pico W maintains the same MQTT connection after WiFi reconnection and continues receiving messages without any issues. In this case, the Pico doesn’t even need to reconnect to the broker—everything remains stable and functional.
Steps to Reproduce:
Log Output:
The problem seems tied to messages being sent to the topic while the Pico W is disconnected from WiFi.