Github Devices Community Docs Blog

Wifi automatic reconnection issue with ESP32

Continuing the discussion from ESP32 BLE gateway dying every day and a half:

@krambriw

I prefer to separate the topic so as to narrow down the issue (strictly the fact that the gateway doesn’t reconnect automaticaly to wifi with certain router is in my point of view a different issue compared to BLE stability)

I have added a modification to the branch below:

Related to this issue on ESP32:

Hello, good news, it seems working fine now!

When the AP is down I see in log the following coming repeatedly:

MQTT client disconnected no BLE scan
*WM: [2] [EVENT] WIFI_REASON: 201
*WM: [2] [EVENT] WIFI_REASON: NO_AP_FOUND
BT Task running on core 0
*WM: [2] [EVENT] WIFI_REASON: 201
*WM: [2] [EVENT] WIFI_REASON: NO_AP_FOUND
MQTT connection…
[E][WiFiClient.cpp:232] connect(): connect on fd 55, errno: 118, “Host is unreachable”
failure_number
81
failed, rc=
-2

When the AP is up again, a new connection is made successfully, mqtt publishing starts again, everything is fine. Tried this several times and every time the ESP32 recovers the wifi connection successfully

One thing I noticed with previous versions was the the BT scanning (until it was turned off in last versions when there was no mqtt connection) always seemed to work even if the wifi was disconnected. So could this wifi disconnect, if it happened for any reason, actually have been the cause why the gateway was experienced as “dead”?

What I mean here is that one type of behavior (mqtt publishing ended) could have been caused by a another problem, i.e. temporary wifi connection error that was never recovered

Anyway, time will tell, so far it looks really good!!

PS In the serial monitor I see several devices being found, including my sonos speakers, but for some reason the text (manufacturerdata) is not readable, is it something in the platformio that can be adjusted, like supporting character set utf-8 or so? Or is it in the actual code where you publish the results to mqtt?

{“id”:“f3:33:41:94:64:d5”,“manufacturerdata”:“�␅␃␑Sonos_Uq9RJ”,“rssi”:-84,“txpower”:0,“distance”:

{“id”:“f3:33:ac:c2:d7:6e”,“manufacturerdata”:“�␅␃␒u1w1PbgkSBO”,“rssi”:-87,“txpower”:0,“distance”:

{“id”:“f3:33:ac:c2:d7:6e”,“manufacturerdata”:“�␅␃␐␁�Dޭ��”,“rssi”:-87,“txpower”:0,“distance”:18.07

Great, thanks for helping me debug this!

I need some investigations so as to see what happens here