ESP32 unable to reconnect to wifi after reboot with Huawei, Fastgate DN8245f2

Hello, I have a problem with a LILYGO TTGO LoRa V2.1 board with the latest firmware (v1.5.0). The installation goes without problems and after completing the initial configuration (wifi and mqtt settings) everything works perfectly. The problem start when a reboot occurs, the board can no longer connect to the wifi network and so it switch to AP mode.

Logs of first boot and parameter setting, everything seems ok.

************* WELCOME TO OpenMQTTGateway **************
N: SSD1306 config initialised
[   138][E][Preferences.cpp:483] getString(): nvs_get_str len fail: SSD1306Config NOT_FOUND
N: No SSD1306 config to load
N: Setup SSD1306 Display end
N: OpenMQTTGateway Version: v1.5.0
*wm:[2] Added Parameter: server
*wm:[2] Added Parameter: port
*wm:[2] Added Parameter: user
*wm:[2] Added Parameter: pass
*wm:[2] Added Parameter: secure
*wm:[2] Added Parameter: cert
*wm:[2] Added Parameter: name
*wm:[2] Added Parameter: topic
*wm:[2] Added Parameter: ota
N: Attempting Wifi connection with saved AP: 0
[  1348][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a
N: Attempting Wifi connection with saved AP: 1
[  2356][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a
N: Attempting Wifi connection with saved AP: 2
[  3363][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a
N: Attempting Wifi connection with saved AP: 3
[  4369][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a
N: Attempting Wifi connection with saved AP: 4
[  5376][E][WiFiSTA.cpp:317] begin(): connect failed! 0x300a
N: Connect your phone to WIFI AP: OpenMQTTGateway_lilygo_rtl_433_ESP with PWD: your_password
*wm:[1] AutoConnect 
*wm:[2] ESP32 event handler enabled 
*wm:[2] Connecting as wifi client... 
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] No wifi saved, skipping 
*wm:[2] Connection result: WL_NO_SSID_AVAIL
*wm:[1] AutoConnect: FAILED 
*wm:[2] Starting Config Portal 
*wm:[2] AccessPoint set password is VALID 
*wm:[2] Disabling STA 
*wm:[2] Enabling AP 
*wm:[1] StartAP with SSID:  OpenMQTTGateway_lilygo_rtl_433_ESP
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal 
*wm:[2] HTTP server started 
*wm:[2] WiFi Scan ASYNC started 
*wm:[2] Config Portal Running, blocking, waiting for clients... 
*wm:[2] Portal Timeout In 120 seconds
*wm:[2] WiFi Scan ASYNC completed in 7249 ms
*wm:[2] WiFi Scan ASYNC found: 28
*wm:[2] Portal Timeout In 98 seconds
[ 31189][E][WebServer.cpp:649] _handleRequest(): request handler not found
*wm:[2] <- Request redirected to captive portal 
*wm:[2] <- HTTP Root 
*wm:[2] Scan is cached 14443 ms ago
[ 31701][E][WebServer.cpp:649] _handleRequest(): request handler not found
*wm:[2] <- Request redirected to captive portal 
*wm:[2] <- HTTP Root 
*wm:[2] Scan is cached 14952 ms ago
[ 31760][E][WebServer.cpp:649] _handleRequest(): request handler not found
*wm:[2] <- Request redirected to captive portal 
*wm:[2] <- HTTP Root 
*wm:[2] Scan is cached 15010 ms ago
*wm:[2] <- HTTP Wifi 
*wm:[2] Scan is cached 17940 ms ago
*wm:[1] 28 networks found
*wm:[2] DUP AP: ****SSID****
*wm:[2] DUP AP: ****SSID****
*wm:[2] AP:  -25 ****MY-SSID****
 .
 .
 .
[ 34871][E][WebServer.cpp:649] _handleRequest(): request handler not found
*wm:[2] <- Request redirected to captive portal 
*wm:[2] <- HTTP Root 
*wm:[2] Scan is cached 18152 ms ago
*wm:[2] Portal Timeout In 94 seconds
*wm:[2] <- HTTP WiFi save  
*wm:[2] Parameters 
*wm:[2] -------------------- 
*wm:[2] server: 192.168.1.10
*wm:[2] port: 1883
*wm:[2] user: ********
*wm:[2] pass: ********
*wm:[2] secure: 
*wm:[2] cert: 
*wm:[2] name: Gateway_433
*wm:[2] topic: OpenMQTT/
*wm:[2] ota: OTAPASSWORD
*wm:[2] -------------------- 
*wm:[2] processing save 
*wm:[2] Connecting as wifi client... 
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] Connecting to NEW AP: ****MY-SSID****
*wm:[1] connectTimeout not set, ESP waitForConnectResult... 
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] Connect to new AP [SUCCESS] 
*wm:[1] Got IP Address: 
*wm:[1] 192.168.1.100 
*wm:[2] [CB] _savewificallback calling 
*wm:[2] shutdownConfigPortal 
[ 77845][E][WebServer.cpp:649] _handleRequest(): request handler not found
*wm:[2] <- Request redirected to captive portal 
*wm:[2] restoring usermode STA
*wm:[2] wifi status: WL_CONNECTED
*wm:[2] wifi mode: STA
*wm:[2] configportal closed 
*wm:[1] config portal exiting 
{
  "mqtt_server": "192.168.1.10",
  "mqtt_port": "1883",
  "mqtt_user": "********",
  "mqtt_pass": "********",
  "mqtt_topic": "OpenMQTT/",
  "gateway_name": "Gateway_433",
  "mqtt_broker_secure": false,
  "mqtt_broker_cert": "",
  "mqtt_ss_index": 0,
  "ota_server_cert": "",
  "ota_pass": "OTAPASSWORD"
}
N: ZgatewayRTL_433 setup done 
N: Switching to RTL_433 Receiver: 433.92Mhz
N: OpenMQTTGateway modules: ["LilyGo_SSD1306","rtl_433"]
N: ************** Setup OpenMQTTGateway end **************
W: MQTT connection...
W: failure_number_mqtt: 1
W: failed, rc=-2
W: MQTT connection...
N: Connected to broker

Logs after reboot, the board is unable to connect with stored credentials and switch to AP mode.

************* WELCOME TO OpenMQTTGateway **************
N: SSD1306 config initialised
[   138][E][Preferences.cpp:483] getString(): nvs_get_str len fail: SSD1306Config NOT_FOUND
N: No SSD1306 config to load
N: Setup SSD1306 Display end
N: OpenMQTTGateway Version: v1.5.0
{
  "mqtt_server": "192.168.1.10",
  "mqtt_port": "1883",
  "mqtt_user": "********",
  "mqtt_pass": "********",
  "mqtt_topic": "OpenMQTT/",
  "gateway_name": "Gateway_433",
  "mqtt_broker_secure": false,
  "mqtt_broker_cert": "",
  "mqtt_ss_index": 0,
  "ota_server_cert": "",
  "ota_pass": "OTAPASSWORD"
}
*wm:[2] Added Parameter: server
*wm:[2] Added Parameter: port
*wm:[2] Added Parameter: user
*wm:[2] Added Parameter: pass
*wm:[2] Added Parameter: secure
*wm:[2] Added Parameter: cert
*wm:[2] Added Parameter: name
*wm:[2] Added Parameter: topic
*wm:[2] Added Parameter: ota
N: Attempting Wifi connection with saved AP: 0
N: Attempting Wifi connection with saved AP: 1
N: Attempting Wifi connection with saved AP: 2
E (7155) wifi:sta is connecting, return error
[  3398][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
N: Attempting Wifi connection with saved AP: 3
E (8166) wifi:sta is connecting, return error
[  4409][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
N: Attempting Wifi connection with saved AP: 4
N: Connect your phone to WIFI AP: OpenMQTTGateway_lilygo_rtl_433_ESP with PWD: your_password
*wm:[1] AutoConnect 
*wm:[2] ESP32 event handler enabled 
*wm:[2] Connecting as wifi client... 
*wm:[2] setSTAConfig static ip not set, skipping 
*wm:[1] Connecting to SAVED AP: ****MY-SSID****
*wm:[0] [ERROR] wifi begin failed 
*wm:[2] 5000 ms timeout, waiting for connect...
*wm:[2] . 
 .
 .
 .
*wm:[2] . 
*wm:[2] Connection result: WL_IDLE_STATUS
*wm:[1] AutoConnect: FAILED 
*wm:[2] Starting Config Portal 
*wm:[2] AccessPoint set password is VALID 
*wm:[2] Disabling STA 
*wm:[2] Enabling AP 
*wm:[1] StartAP with SSID:  OpenMQTTGateway_lilygo_rtl_433_ESP
*wm:[2] [EVENT] WIFI_REASON:  8
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal 
*wm:[2] HTTP server started 
*wm:[2] WiFi Scan ASYNC started 
*wm:[2] Config Portal Running, blocking, waiting for clients... 
*wm:[2] Portal Timeout In 120 seconds

I tried erase the flash memory with both https://espressif.github.io/esptool-js/ and ESPTool.py but it didn’t solve.

Hope someone can give me some suggestions.
Thank you

Hello,

Is it a reboot that you trigger yourself with an mqtt command?

Also if you wait for the wifi manage portal to timeout (>120s) does the board reconnect to wifi ?

Same board (Lilygo TTGO LorRa V2.1), same problem: it doesn’t reconnect to a wifi after a reboot. (If I turn off the USB power or press the reset button on board)

Could you try to assign a manual IP Address to the ESP32 ?

Suspecting an issue with the DHCP

No, it is due to a simple power off and power on of the board, unplugging the usb cable.

After the timeout it reboot and goes in a loop: try to connect to wifi → switch to AP mode → wait 120 → reboot

A strange thing is that when the ESP32 try to connect to the wifi network, on the router side it appears online for few seconds and then goes offline.

I take a look at the documentation and give it a try.
Will update

Thanks, also please share your router model

I build the firmware with static ip editing the User_config.h

#define NetworkAdvancedSetup true //uncomment if you want to set advanced network parameters, not uncommented you can set the IP and MAC only
#ifdef NetworkAdvancedSetup
#  if defined(ESP8266) || defined(ESP32)
const byte ip[] = {192, 168, 1, 5}; //IP address of the gateway, already defined for arduino below
#  endif
const byte gateway[] = {192, 168, 1, 1};
const byte Dns[] = {1, 1, 1, 1};
const byte subnet[] = {255, 255, 255, 0};
#endif

Now the ESP32 is able to reconnect to the wifi network also after reboot, but there are other strange things. Initialy it failed to connect to wifi and goes in AP mode for few seconds, than switch to STA. Finally it can not resolve github.com

************* WELCOME TO OpenMQTTGateway **************
N: SSD1306 config initialised
[   141][E][Preferences.cpp:483] getString(): nvs_get_str len fail: SSD1306Config NOT_FOUND
N: No SSD1306 config to load
N: Setup SSD1306 Display end
N: OpenMQTTGateway Version: version_tag
{
  "mqtt_server": "192.168.1.10",
  "mqtt_port": "1883",
  "mqtt_user": "********",
  "mqtt_pass": "********",
  "mqtt_topic": "OpenMQTT/",
  "gateway_name": "Gateway_433",
  "mqtt_broker_secure": false,
  "mqtt_broker_cert": "",
  "mqtt_ss_index": 0,
  "ota_server_cert": "",
  "ota_pass": "OTAPASSWORD"
}
*wm:[2] Added Parameter: server
*wm:[2] Added Parameter: port
*wm:[2] Added Parameter: user
*wm:[2] Added Parameter: pass
*wm:[2] Added Parameter: secure
*wm:[2] Added Parameter: cert
*wm:[2] Added Parameter: name
*wm:[2] Added Parameter: topic
*wm:[2] Added Parameter: ota
N: Attempting Wifi connection with saved AP: 0
N: Attempting Wifi connection with saved AP: 1
N: Attempting Wifi connection with saved AP: 2
E (7171) wifi:sta is connecting, return error
[  3401][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
N: Attempting Wifi connection with saved AP: 3
E (8183) wifi:sta is connecting, return error
[  4413][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
N: Attempting Wifi connection with saved AP: 4
N: Connect your phone to WIFI AP: OpenMQTTGateway_lilygo_rtl_433_ESP with PWD: your_password
*wm:[1] AutoConnect 
*wm:[2] ESP32 event handler enabled 
*wm:[2] Connecting as wifi client... 
*wm:[2] Custom static IP/GW/Subnet/DNS 
*wm:[2] Custom STA IP/GW/Subnet 
*wm:[1] STA IP set: 192.168.1.5
*wm:[1] Connecting to SAVED AP: ****MY-SSID****
*wm:[2] 5000 ms timeout, waiting for connect...
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS 
*wm:[2] Connected in 524 ms
*wm:[1] STA IP Address: 192.168.1.5
N: ZgatewayRTL_433 setup done 
N: Switching to RTL_433 Receiver: 433.92Mhz
N: OpenMQTTGateway modules: ["LilyGo_SSD1306","rtl_433"]
N: ************** Setup OpenMQTTGateway end **************
W: MQTT connection...
N: Connected to broker
N: Send on /SYStoMQTT msg {"uptime":14,"version":"version_tag","discovery":true,"env":"lilygo-rtl_433","freemem":127772,"mqttport":"1883","mqttsecure":false,"tempc":47.22222,"freestack":4588,"rssi":-27,"SSID":"****MY-SSID****","BSSID":"**:**:**:**:**:**","ip":"192.168.1.5","mac":"**:**:**:**:**:**","actRec":3,"mhz":433.92,"RTLRssiThresh":-82,"RTLRssi":-103,"RTLAVGRssi":0,"RTLCnt":0,"RTLOOKThresh":15,"modules":["LilyGo_SSD1306","rtl_433"]}
N: Send on /SSD1306toMQTT msg {"onstate":true,"brightness":50,"displaymetric":true,"display-flip":true,"idlelogo":true,"log-oled":false,"json-oled":true}
N: Update check[ 14894][E][WiFiGeneric.cpp:1476] hostByName(): DNS Failed for github.com
E: Error on HTTP request

The router is a Huawei DN8245f2 from my ISP

1 Like

Same problem, also same router: Huawei, Fastgate DN8245f2

1 Like

thanks, and if you put a static IP on the router configuration
Maybe @Perfra can do the test

Also could you check that your router is with the latest firmware update

I tried to make a dhcp reservation but nothing change.

Unfortunately, router firmware updates are managed directly by the ISP and I can’t verify them. I confirm that using my smartphone in AP mode instead of the router, everything works perfectly.
Can you give me some hints to better debug the error?

What are your router settings regarding DHCP lease time and lease pool

The DHCP lease time is set to the maximum available 48h and the ip address range is from 192.168.1.100 to 192.168.1.254

Do you have access to the router logs when the esp32 is trying to connect?

Hi @bgdev and @Perfra

While I have a different router and a slightly different behaviour, I also experience re-connection issues with my ESP32 based gateways.

I have created a test build which, as a stopgap measure, solves my problems. It would be great if you could try out build SHA f09001 as well, so we can see if our connection problems might have a similar root cause.

Thanks

Unfortunately the router has no option to view the logs.

It works :partying_face:
I made several tests, both by restarting the board with the reset button and by removing the power supply. The board always reconnect to the wifi network. I found some errors in the logs but finally it get the connection.

************* WELCOME TO OpenMQTTGateway **************
N: SSD1306 config initialised
N: No SSD1306 config to load
N: Setup SSD1306 Display end
N: OpenMQTTGateway Version: f09001
{
  "mqtt_server": "192.168.1.10",
  "mqtt_port": "1883",
  "mqtt_user": "********",
  "mqtt_pass": "********",
  "mqtt_topic": "OpenMQTT/",
  "gateway_name": "Gateway_433",
  "mqtt_broker_secure": false,
  "mqtt_broker_cert": "",
  "mqtt_ss_index": 0,
  "ota_server_cert": "",
  "ota_pass": "OTAPASSWORD"
}*wm:[2] Added Parameter: server
*wm:[2] Added Parameter: port
*wm:[2] Added Parameter: user
*wm:[2] Added Parameter: pass
*wm:[2] Added Parameter: secure
*wm:[2] Added Parameter: cert
*wm:[2] Added Parameter: name
*wm:[2] Added Parameter: topic
*wm:[2] Added Parameter: ota
N: Attempting Wifi connection with saved AP: 0
N: Attempting Wifi connection with saved AP: 1
E (3672) wifi:sta is connecting, return error
[E][WiFiSTA.cpp:221] begin(): connect failed!
N: Attempting Wifi connection with saved AP: 2
E (4674) wifi:sta is connecting, return error
[E][WiFiSTA.cpp:221] begin(): connect failed!
N: ZgatewayRTL_433 setup done 
N: Switching to RTL_433 Receiver: 433.92Mhz
N: OpenMQTTGateway modules: ["LilyGo_SSD1306","rtl_433"]
N: ************** Setup OpenMQTTGateway end **************

Thanks

1 Like

Wow!!! It worked perfectly! Many thanks :wink:

1 Like

Hi @DigiH, could you point me to the branch / commit used for this test version? I am unable to find it (my bad probably). I am having exactly the same problem with a Lilygo TTGO T7 and an ASUS XT8 router. Thanks,

Hi @peralta, not your bad, the test version was only available for a day, until it got overwritten by the nightly development builds again :wink:

I’ll start off another test build, which takes just over an hour to finish - will post the web upload link once it is done.

@peralta It took longer as were some issues with getting the test built to build and being published. It is avaialble at

with the hash feb4f0.

Let us know if you managed to install it before the nightly builds overwrite it again. If so we can publish again tomorrow at an earlier time, and once installed if it solved the issue with your ASUS XT8 router.

Thanks

Hi @DigiH - thank you for your quick answer. Flashed already.
From a few short tests (restart through MQTT or reset button), it behaves significantly better: just after reset it usually fails to connect, but one or two automatic reboots later it ends up connecting. I’ll keep monitoring it during the next few hours.
A case where it always works (this version and also unmodified 1.5.1) is after erasing the wifi credentials (and adding them again), where it always connects on first try (but does not after reboot).

1 Like