tonyp7 / esp32-wifi-manager

Captive Portal for ESP32 that can connect to a saved wireless network or start an access point where you can connect to existing wifis.
MIT License
652 stars 214 forks source link

ESP_ERROR_CHECK fails during user connection #71

Closed akhilv1 closed 3 years ago

akhilv1 commented 4 years ago

Hi, I found a bug in the connection process where sometimes the event ORDER_START_WIFI_SCAN occurs during the execution of ORDER_CONNECT_STA which causes the esp to reset due to an assert failure for the scan because the sta is attempting to connect.

I fixed this by adding a boolean that gets set to true in ORDER_CONNECT_STA if msg.param == CONNECTION_REQUEST_USER, and only performing the wifi scan when the flag is false. this flag needs to be reset to false if the password is wrong under EVENT_STA_DISCONNECTED.

Here's the serial output: I (13123) wifi_manager: SYSTEM_EVENT_AP_STACONNECTED I (13433) dns_server: Replying to DNS request for captive.apple.com from 10.10.0.2 I (14273) tcpip_adapter: softAP assign IP to station,IP is: 10.10.0.2 I (34383) wifi_manager: MESSAGE: ORDER_CONNECT_STA W (35903) wifi: sta_scan: STA is connecting, scan are not allowed! ESP_ERROR_CHECK failed: esp_err_t 0xffffffff (ESP_FAIL) at 0x4008c7a0 0x4008c7a0: _esp_error_check_failed at /Users/neo/esp/esp-idf/components/esp32/panic.c:731

file: "/Users/neo/esp/NeoFW/main/wifi_manager.c" line 766 func: wifi_manager expression: esp_wifi_scan_start(&scan_config, false)

ELF file SHA256: 6f3485e5d5133654cca74dfc79b19dfeb7d2ed440c7003b076ace0c65b2e027f

Backtrace: 0x4008c21d:0x3ffc0460 0x4008c7a3:0x3ffc0480 0x400d6c21:0x3ffc04a0 0x4008e79d:0x3ffc0620 0x4008c21d: invoke_abort at /Users/neo/esp/esp-idf/components/esp32/panic.c:157

0x4008c7a3: _esp_error_check_failed at /Users/neo/esp/esp-idf/components/esp32/panic.c:732

0x400d6c21: wifi_manager at /Users/neo/esp/NeoFW/main/wifi_manager.c:751 (discriminator 2)

0x4008e79d: vPortTaskWrapper at /Users/neo/esp/esp-idf/components/freertos/port.c:143

Skinner927 commented 4 years ago

What about using ESP_ERROR_CHECK_WITHOUT_ABORT instead of ESP_ERROR_CHECK? https://github.com/tonyp7/esp32-wifi-manager/blob/master/src/wifi_manager.c#L776

Or is it advantageous to restart the device?

tonyp7 commented 3 years ago

@akhilv1 a boolean is not an acceptable thread synchronization mechanism. However I think this can easily be fixed by checking for the event group bits CONNECTION_REQUEST_USER or CONNECTION_REQUEST_RESTORE_CONNECTION.

I mark this as bug and include in milestone 3.2