Esp8266 disconnects from WIFI and doesn't reconnect automatically

#1

If you are asking a question, please follow this template:

  1. Esp8266 disconnects from station wifi after a few hours and doesn’t reconnect automatically. Need to restart the chip by recycling power.

  2. Here is the log output

mongoose.c:4912         0x3fff12ec mbedtls_ssl_flush_output() returned -78 (-0x004e)
mongoose.c:4912         0x3fff12ec mbedtls_ssl_write_record() returned -78 (-0x004e)
mongoose.c:4912         0x3fff12ec mbedtls_ssl_send_alert_message() returned -78 (-0x004e)
mgos_mqtt_conn.c:256    MQTT0 Disconnect
mgos_mqtt_conn.c:549    MQTT0 connecting after 2096 ms
mgos_mqtt_conn.c:471    MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113              /zzz_UPSTREAM -> {"data":{"eparams":{"AIRMS":0.00,"AWATT":0.00,"BIRMS":0.00,"BWATT":0.00,"CIRMS":0.00,"CWATT":0.00},"meters":{"AMETER":0.01,"BMETER":0.01,"CMETER":0.01}}}
mongoose.c:12068        Failed to resolve 'xxx.iot.us-east-2.amazonaws.com', server 192.168.31.1
mgos_mqtt_conn.c:229    MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256    MQTT0 Disconnect
mgos_mqtt_conn.c:549    MQTT0 connecting after 3640 ms
mgos_mqtt_conn.c:471    MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113              /zzz_UPSTREAM -> {"data":{"eparams":{"AIRMS":0.00,"AWATT":0.00,"BIRMS":0.00,"BWATT":0.00,"CIRMS":0.00,"CWATT":0.00},"meters":{"AMETER":0.01,"BMETER":0.01,"CMETER":0.01}}}
mongoose.c:12068        Failed to resolve 'xxx.iot.us-east-2.amazonaws.com', server 192.168.31.1
mgos_mqtt_conn.c:229    MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256    MQTT0 Disconnect
mgos_mqtt_conn.c:549    MQTT0 connecting after 8318 ms
mgos_mqtt_conn.c:471    MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113              /zzz_UPSTREAM -> {"data":{"eparams":{"AIRMS":0.00,"AWATT":0.00,"BIRMS":0.00,"BWATT":0.00,"CIRMS":0.00,"CWATT":0.00},"meters":{"AMETER":0.01,"BMETER":0.01,"CMETER":0.01}}}
main.c:113              /zzz_UPSTREAM -> {"data":{"eparams":{"AIRMS":0.00,"AWATT":0.00,"BIRMS":0.00,"BWATT":0.00,"CIRMS":0.00,"CWATT":0.00},"meters":{"AMETER":0.01,"BMETER":0.01,"CMETER":0.01}}}
mongoose.c:12068        Failed to resolve 'xxx.iot.us-east-2.amazonaws.com', server 192.168.31.1
mgos_mqtt_conn.c:229    MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256    MQTT0 Disconnect
mgos_mqtt_conn.c:549    MQTT0 connecting after 17464 ms
mgos_mqtt_conn.c:471    MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113              /zzz_UPSTREAM -> {"data":{"eparams":{"AIRMS":0.00,"AWATT":0.00,"BIRMS":0.00,"BWATT":0.00,"CIRMS":0.00,"CWATT":0.00},"meters":{"AMETER":0.01,"BMETER":0.01,"CMETER":0.01}}}
mongoose.c:12068        Failed to resolve 'xxx-ats.iot.us-east-2.amazonaws.com', server 192.168.31.1
mgos_mqtt_conn.c:229    MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256    MQTT0 Disconnect
mgos_mqtt_conn.c:549    MQTT0 connecting after 30614 ms
mgos_mqtt_conn.c:471    MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113              /zzz_UPSTREAM -> {"data":{"eparams":{"AIRMS":0.00,"AWATT":0.00,"BIRMS":0.00,"BWATT":0.00,"CIRMS":0.00,"CWATT":0.00},"meters":{"AMETER":0.01,"BMETER":0.01,"CMETER":0.01}}}
mongoose.c:12068        Failed to resolve 'xxx.iot.us-east-2.amazonaws.com', server 192.168.31.1
mgos_mqtt_conn.c:229    MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256    MQTT0 Disconnect
mgos_mqtt_conn.c:549    MQTT0 connecting after 55514 ms
mgos_mqtt_conn.c:471    MQTT0 connecting to xxx-east-2.amazonaws.com:8883
  • Please help me with the quick fix for this asap.
#2

Doesn’t look like you have shared enough logs. I’d assume you need to at least share the events related to WiFi (rather than MQTT) for anyone to be able to help

#3

This is the total log. The problem starts from these lines
mongoose.c:4912 0x3fff12ec mbedtls_ssl_flush_output() returned -78 (-0x004e)
mongoose.c:4912 0x3fff12ec mbedtls_ssl_write_record() returned -78 (-0x004e)
mongoose.c:4912 0x3fff12ec mbedtls_ssl_send_alert_message() returned -78 (-0x004e)

After that, the log sort of keeps repeating.

#4

There is no evidence in your log of wifi disconnection.
This line

Failed to resolve 'xxx.iot.us-east-2.amazonaws.com', server 192.168.31.1

shows a DNS issue rather than a wifi one.

#5

Here is even more detailed log. The issue starts when esp8266 disconnects from WIFI and doesn’t automatically reconnect.

main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:4912 0x3fff12ec mbedtls_ssl_flush_output() returned -78 (-0x004e)
mongoose.c:4912 0x3fff12ec mbedtls_ssl_write_record() returned -78 (-0x004e)
mongoose.c:4912 0x3fff12ec mbedtls_ssl_send_alert_message() returned -78 (-0x004e)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 2096 ms
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.us-east-2.amazonaws.com:8883
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 3640 ms
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 8318 ms
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 17464 ms
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 30614 ms
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 55514 ms
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
esp_main.c:145 SDK: state: 5 -> 2 (3c0)
esp_main.c:145 SDK: rm 0
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 3
mgos_net.c:82 WiFi STA: disconnected
mgos_net.c:86 WiFi STA: connecting
esp_main.c:145 SDK: scandone
esp_main.c:145 SDK: state: 2 -> 2 (b0)
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 57762 ms
esp_main.c:145 SDK: state: 2 -> 0 (2)
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 2
mgos_net.c:82 WiFi STA: disconnected
mgos_wifi.c:345 WiFi STA: Connect timeout
mgos_wifi.c:88 WiFi STA: Using config 0 (Xiaomi_EFB4)
mgos_wifi.c:270 WiFi STA: Connecting to Xiaomi_EFB4
mgos_net.c:86 WiFi STA: connecting
esp_main.c:145 SDK: scandone
esp_main.c:145 SDK: state: 0 -> 2 (b0)
esp_main.c:145 SDK: state: 2 -> 3 (0)
esp_main.c:145 SDK: state: 3 -> 5 (10)
esp_main.c:145 SDK: add 0
esp_main.c:145 SDK: aid 3
esp_main.c:145 SDK: cnt
esp_main.c:145 SDK: state: 5 -> 2 (fc0)
esp_main.c:145 SDK: rm 0
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 15
mgos_net.c:82 WiFi STA: disconnected
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
mgos_wifi.c:345 WiFi STA: Connect timeout
mgos_wifi.c:88 WiFi STA: Using config 0 (Xiaomi_EFB4)
esp_main.c:145 SDK: state: 2 -> 0 (0)
mgos_wifi.c:270 WiFi STA: Connecting to Xiaomi_EFB4
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 202
mgos_net.c:86 WiFi STA: connecting
mgos_net.c:82 WiFi STA: disconnected
esp_main.c:145 SDK: scandone
esp_main.c:145 SDK: state: 0 -> 2 (b0)
esp_main.c:145 SDK: state: 2 -> 3 (0)
esp_main.c:145 SDK: state: 3 -> 5 (10)
esp_main.c:145 SDK: add 0
esp_main.c:145 SDK: aid 3
esp_main.c:145 SDK: cnt
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 58023 ms
esp_main.c:145 SDK: state: 5 -> 2 (fc0)
esp_main.c:145 SDK: rm 0
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 15
mgos_net.c:82 WiFi STA: disconnected
mgos_wifi.c:345 WiFi STA: Connect timeout
mgos_wifi.c:88 WiFi STA: Using config 0 (Xiaomi_EFB4)
esp_main.c:145 SDK: state: 2 -> 0 (0)
mgos_wifi.c:270 WiFi STA: Connecting to Xiaomi_EFB4
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 202
mgos_net.c:86 WiFi STA: connecting
mgos_net.c:82 WiFi STA: disconnected
esp_main.c:145 SDK: scandone
esp_main.c:145 SDK: state: 0 -> 2 (b0)
esp_main.c:145 SDK: state: 2 -> 3 (0)
esp_main.c:145 SDK: state: 3 -> 5 (10)
esp_main.c:145 SDK: add 0
esp_main.c:145 SDK: aid 3
esp_main.c:145 SDK: cnt
esp_main.c:145 SDK: state: 5 -> 2 (fc0)
esp_main.c:145 SDK: rm 0
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 15
mgos_net.c:82 WiFi STA: disconnected
mgos_wifi.c:345 WiFi STA: Connect timeout
mgos_wifi.c:88 WiFi STA: Using config 0 (Xiaomi_EFB4)
esp_main.c:145 SDK: state: 2 -> 0 (0)
mgos_wifi.c:270 WiFi STA: Connecting to Xiaomi_EFB4
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 202
mgos_net.c:86 WiFi STA: connecting
mgos_net.c:82 WiFi STA: disconnected
esp_main.c:145 SDK: scandone
esp_main.c:145 SDK: state: 0 -> 2 (b0)
esp_main.c:145 SDK: state: 2 -> 3 (0)
esp_main.c:145 SDK: state: 3 -> 5 (10)
esp_main.c:145 SDK: add 0
esp_main.c:145 SDK: aid 3
esp_main.c:145 SDK: cnt
mgos_mqtt_conn.c:471 MQTT0 connecting to xxx.iot.us-east-2.amazonaws.com:8883
esp_main.c:145 SDK: state: 5 -> 2 (fc0)
esp_main.c:145 SDK: rm 0
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 15
mgos_net.c:82 WiFi STA: disconnected
main.c:113 /zzz_UPSTREAM -> {“data”:{“eparams”:{“AIRMS”:0.00,“AWATT”:0.00,“BIRMS”:0.00,“BWATT”:0.00,“CIRMS”:0.00,“CWATT”:0.00},“meters”:{“AMETER”:0.01,“BMETER”:0.01,“CMETER”:0.01}}}
mongoose.c:12068 Failed to resolve ‘xxx.iot.us-east-2.amazonaws.com’, server 192.168.31.1
mgos_mqtt_conn.c:229 MQTT0 TCP connect error (-1)
mgos_mqtt_conn.c:256 MQTT0 Disconnect
mgos_mqtt_conn.c:549 MQTT0 connecting after 64674 ms
mgos_wifi.c:345 WiFi STA: Connect timeout
mgos_wifi.c:88 WiFi STA: Using config 0 (Xiaomi_EFB4)
esp_main.c:145 SDK: state: 2 -> 0 (0)
mgos_wifi.c:270 WiFi STA: Connecting to Xiaomi_EFB4
mgos_wifi.c:118 WiFi STA: Disconnected, reason: 202
mgos_net.c:86 WiFi STA: connecting
mgos_net.c:82 WiFi STA: disconnected
esp_main.c:145 SDK: scandone
esp_main.c:145 SDK: state: 0 -> 2 (b0)
esp_main.c:145 SDK: state: 2 -> 3 (0)
esp_main.c:145 SDK: state: 3 -> 5 (10)

#6

In my experience I’ve seen thinks like this when my WiFi router starts to play up. (202 and 3)
From memory I would get reason 15 when I got the WiFi password wrong, but that doesn’t seem to match what you are saying.

When I’ve been doing lots of connects/disconnects as part of dev work I’ve seen this, then resolved by restarting my router.

#7

The thing is that esp8266 connects to the same router when restarted. If it is a router issue, the chip shouldn’t connect even after restarting. And this is happening with many different routers. The chips show the same behavior after every 6-12 hours. This issue never happens with ESP32 chip.

#8

Does it solve with a reset or a power-on reset ?
Looks like your comms are lost and the OS decides to disconnect and reconnect after realizing something is wrong.
I’ve seen this happening with some Access Points and after a new program load.
How is your heap before this happens ? Are you checking MQTT send function’s return value ?