knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.78k stars 1.46k forks source link

esp8266 lost connection every 30 min #1018

Open BruceAKABear opened 1 year ago

BruceAKABear commented 1 year ago

I have meet one strange problem, esp8266 call connected() methd will return false every 30 min actually the hartbeat is still working, in my logic when connected() return I will reboot whole system. why connected() will return false?

` hearbeat:

2023-07-05T10:45:47+08:00 [MQTT] 13388860@10.5.171.61:54257 msg: mqtt_packet_received, packet: PINGREQ(Q0, R0, D0) 2023-07-05T10:45:47+08:00 [MQTT] 13388860@10.5.171.61:54257 msg: mqtt_packet_sent, packet: PINGRESP(Q0, R0, D0)

my logic in connect:

2023-07-05T10:45:57+08:00 [MQTT] 13388860@10.5.171.61:53948 msg: mqtt_packet_received, packet: CONNECT(Q0, R0, D0),ClientId=13388860, ProtoName=MQTT, ProtoVsn=4, CleanStart=true,

`

my logic in loop:

`

void loop() { if (WiFi.status() != WL_CONNECTED) { connectWifi(); } else { if (!mqttClient.connected()) { connectMqtt(); } } mqttClient.loop(); } `

superbool commented 11 months ago

Check your wifi is stable.