2018/04/25

ESP32 - Solving the problem of WiFiManager "failed to connect"

This post is a quick summary on how to solve the always "failed to connect" issue when using WiFiManager on ESP32.

The Symptom

The password is saved but the Connection Result always returns 1 (Failed to connect).

*WM: WiFi save
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Connection result:
*WM: 1
*WM: Failed to connect.

If you reset manually the board the connection will established, so the password is correctly stored.
I tried with old Arduino core version and all functionality work correctly, so should be a problem whit some modification on new commit (is there also some IDF sdk update)

The Solution

The problem could be fixed by following the steps below:

1. Locate "WiFiManager.cpp" for ESP32.

In my case, it's at "C:\Users\WeiHsiungHuang\Documents\Arduino\hardware\espressif\esp32\libraries\WiFiManager-esp32".

Note, Be sure not to mix the WiFiManager for ESP8266 with the WiFiManager for ESP32!!

2. Open "WiFiManager.cpp" with editor and search for the phrase "Failed to connect". In my case, it's at line 215.


3. Add the below 2 lines of code immediately below DEBUG_WM(F("Failed to connect."));

ESP.restart();
delay(1000);


4. Save "WiFiManager.cpp" and exit the editor. Recompile and upload the sketch.

Serial Monitor Output

Immediately after "Failed to connect..." appears, the ESP32 is restarted to connect to the selected AP.

*WM: WiFi save
*WM: Parameter
*WM: server
*WM: Qqqq
*WM: Parameter
*WM: port
*WM: 9999
*WM: Parameter
*WM: blynk
*WM: Aaaaa
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Connection result: 
*WM: 1
*WM: Failed to connect.
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58

mounting FS...
mounted file system
reading config file
opened config file
{"mqtt_server":"Qqqq","mqtt_port":"9999","blynk_token":"Aaaaa"}
parsed json
*WM: Adding parameter
*WM: server
*WM: Adding parameter
*WM: port
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.2.23
connected...yeey :)
local ip
192.168.2.23

Reference:

Connection problem only on last esp32 Core
https://github.com/zhouhan0126/WIFIMANAGER-ESP32/issues/1

--------------------------------------------------------------------------------------------------------------------------

Note,

The problem disappears after I updated the Arduino-ESP32 installed on my computer to the latest version at https://github.com/espressif/arduino-esp32 (see screenshot below) and tried the same sketch using the original "WiFiManager.cpp" without the above modification.


No comments:

Post a Comment