MQTT disconnect when using WiFi
Posted: Tue Apr 23, 2024 11:53 am
Hello,
I have a problem with MQTT disconnect while connected to network via WiFi. I think that disconnect occurs when ESP32 client doesn't get ACK after message is sent. When transport_base timeout got triggered, MQTT reconnect is performed and ESP32 device is offline for 10 - 30 seconds. After that it connect to MQTT broker and continue to work. This disconnect event happens periodically, but time between disconnect vary from 2 to 15 or more minutes.
here is Wireshark output (10.0.2.82 is broker, 10.0.2.49 is ESP32 client)
and here is ESP32 log output with DEBUG log level:
My question: is there any solution for this exept disconnect/connect? 10 - 30 seconds is too much time my device is "offline" for my application.
Thanks!
I have a problem with MQTT disconnect while connected to network via WiFi. I think that disconnect occurs when ESP32 client doesn't get ACK after message is sent. When transport_base timeout got triggered, MQTT reconnect is performed and ESP32 device is offline for 10 - 30 seconds. After that it connect to MQTT broker and continue to work. This disconnect event happens periodically, but time between disconnect vary from 2 to 15 or more minutes.
here is Wireshark output (10.0.2.82 is broker, 10.0.2.49 is ESP32 client)
and here is ESP32 log output with DEBUG log level:
D (1668006) mqtt_client: Sent PING successful
D (1668065) mqtt_client: mqtt_message_receive: first byte: 0xd0
D (1668066) mqtt_client: mqtt_message_receive: read "remaining length" byte: 0x0
D (1668068) mqtt_client: mqtt_message_receive: total message length: 2 (already read: 2)
D (1668076) mqtt_client: msg_type=13, msg_id=0
D (1668080) mqtt_client: MQTT_MSG_TYPE_PINGRESP
D (1699050) transport_base: poll_write: select - Timeout before any socket was ready!
W (1699050) transport_base: Poll timeout or error, errno=Success, fd=54, timeout_ms=2000
E (1699056) mqtt_client: Writing didn't complete in specified timeout: errno=0
D (1699065) mqtt_client: Reconnect after 10000 ms
D (1699069) event: running post MQTT_EVENTS:2 with handler 0x400d7e18 and context 0x3ffb8948 on loop 0x3ffb8848
D (1699079) MQTT: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (1699086) MQTT: MQTT_EVENT_DISCONNECTED
My question: is there any solution for this exept disconnect/connect? 10 - 30 seconds is too much time my device is "offline" for my application.
Thanks!