-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
I'm experiencing frequent reconnections when using PubSubClient on an ESP32 connected to a Mosquitto 2.0.22 broker via a smartphone hotspot (4G/WiFi). The client repeatedly disconnects and reconnects within seconds, causing a loop of "Client <client_id> already connected, closing old connection" in the Mosquitto log. This happens even when the network signal is relatively stable.
The ESP32 reconnects frequently (every 1–4 seconds), as seen in the Mosquitto log:
2025-09-24 15:03:19: New connection from 36.67.33.97:54867 on port 1883.
2025-09-24 15:03:19: Client lidya already connected, closing old connection.
2025-09-24 15:03:19: New client connected from 36.67.33.97:54867 as lidya (p2, c1, k60, u'lidya').
2025-09-24 15:03:23: New connection from 36.67.33.97:63186 on port 1883.
2025-09-24 15:03:23: Client lidya already connected, closing old connection.
The client reconnects with different TCP ports, and the broker closes the old connection. This creates a loop, overloading the broker and duplicating messages.
Questions
- Is there a recommended way to implement reconnect backoff in PubSubClient for unstable networks?
- Could the keep-alive handling be improved to better tolerate mobile network fluctuations?
- Are there known issues with PubSubClient on ESP32 when using smartphone hotspots?
Metadata
Metadata
Assignees
Labels
No labels