Inconsistent connection to WPA3-Personal-Transition security mode
Posted: Sat Feb 14, 2026 10:08 pm
I'm trying to connect ESP32-S3 to any WiFi AP irrespective of its security mode following a successful WiFi provisioning process. Here's my code:
Here's a log of what happens after successful provisioning:
As you can see from the bolded part of the log, despite having correct WiFi SSID and password, ESP32-S3 is unable to connect to the WiFi. Sometimes it does, but mostly it doesn't. When it does, it takes about 5 tries, and if it doesn't successfully connect by the 6th try, a disconnect event occurs, emitting the WIFI_EVENT_STA_DISCONNECTED WIFI event. Couple of questions:
1. How can I ensure that ESP32-S3 makes a successful WiFi connection consistently, especially when the WiFi security mode is WPA3-Personal-Transition (presume this is the same as WIFI_AUTH_WPA2_WPA3_PSK?)
2. Why does it take esp_wifi_connect API so many tries to successfully establish connection to the WiFi router?
3. Is there a way of manually increasing the number of retries so the disconnect event isn't triggered after 6 unsuccessful attempts?
I never have this issue with WPA/WPA2_PSK security mode.
Code: Select all
ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, (const void *) sec_params, service_name, service_key)); //This completes successfully and emits WIFI_PROV_STOPPED_BIT upon completion
xEventGroupWaitBits(wifi_event_group, WIFI_PROV_STOPPED_BIT, pdFALSE, pdTRUE, portMAX_DELAY);
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &wifi_sta_config));
wifi_sta_config.sta.scan_method = WIFI_ALL_CHANNEL_SCAN;
wifi_sta_config.sta.failure_retry_cnt = 5;
wifi_sta_config.sta.sae_pwe_h2e = WPA3_SAE_PWE_BOTH;
wifi_sta_config.sta.pmf_cfg.capable = 1;
wifi_sta_config.sta.pmf_cfg.required = 0;
if (wifi_set_authmode(&wifi_sta_config) != ESP_OK) {//determines correct authmode of AP to which SSID from provisioning process pertains to allow ESP32-S3 to connect to any WiFi AP
wifi_sta_config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
}
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_sta_config));
esp_wifi_connect();Code: Select all
esp_err_t wifi_set_authmode(wifi_config_t *sta_cfg){
wifi_ap_record_t ap_record;
wifi_scan_config_t scan_config = {
.ssid = (uint8_t *)sta_cfg->sta.ssid,
.show_hidden = true,
.scan_type = WIFI_SCAN_TYPE_ACTIVE,
};
if (!wifi_stopped){
ESP_ERROR_CHECK(esp_wifi_disconnect());
xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT | WIFI_FAILED_BIT);
vTaskDelay(pdMS_TO_TICKS(100));
}
for (int i = 0; i < 5; i++){ //5 retries
if (esp_wifi_scan_start(&scan_config, true) == ESP_OK) {
uint16_t number = 1;
if (esp_wifi_scan_get_ap_records(&number, &ap_record) == ESP_OK && number > 0) {
ESP_LOGI(TAG, "Success! Found AP on attempt %d. Security: %d", i, ap_record.authmode);
if (ap_record.authmode == 7){//8 will accommodate both WPA2_PSK and WPA3_PSK, but 7 will only accommodate WPA3_PSK
sta_cfg->sta.threshold.authmode = 8;
} else {
sta_cfg->sta.threshold.authmode = ap_record.authmode;
}
return ESP_OK;
}
ESP_LOGW(TAG, "Scan attempt %d failed to find AP.", i);
if (i < EXAMPLE_ESP_MAXIMUM_RETRY - 1) {
vTaskDelay(pdMS_TO_TICKS(SCAN_RETRY_DELAY_MS));
}
}
}
ESP_LOGE(TAG, "Security level for WiFi access point with SSID: %.32s not found", sta_cfg->sta.ssid);
return ESP_ERR_NOT_FOUND;
}
Code: Select all
I (2005978) ezzle_event_loop: Provisioning successful
I (2009548) NimBLE: GAP procedure initiated: stop advertising.
I (2009548) NimBLE: GAP procedure initiated: stop advertising.
I (2009548) NimBLE: GAP procedure initiated: terminate connection; conn_handle=1 hci_reason=19
I (2009628) wifi_prov_mgr: Provisioning stopped
I (2009638) wifi_prov_scheme_ble: BTDM memory released
I (2009638) ezzle_event_loop: Deinitilizing wifi prov event
I (2009648) ezzle_wifi_provision: Starting WiFi connection
I (2009648) ezzle_wifi_service: Stopping existing WiFi process
I (2009658) wifi:state: run -> init (0x0)
I (2009668) wifi:pm stop, total sleep time: 3768086 us / 4739068 us
I (2009668) wifi:<ba-del>idx:0, tid:7
I (2009668) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2009678) ezzle_event_loop: Disconnected from WiFi
I (2009688) ezzle_event_loop: Station stopped
I (2009718) wifi:flush txq
I (2009718) wifi:stop sw txq
I (2009718) wifi:lmac stop hw txq
I (2009718) wifi:mode : sta (30:30:f9:73:cd:94)
I (2009718) wifi:enable tsf
I (2009718) ezzle_event_loop: Station started
I (2009718) ezzle_wifi_service: Stopping existing WiFi process
I (2009828) ezzle_wifi_service: Scanning for SSID: MyWiFi to determine security...
I (2012328) ezzle_wifi_service: This is attempt number: 0
I (2012328) ezzle_wifi_service: Success! Found AP on attempt 0. Security: 7
I (2012328) ezzle_wifi_service: Return authmode from wifi_set_authmode: 8
[b]I (2015748) wifi:new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2015748) wifi:state: init -> auth (0xb0)
I (2020108) wifi:state: auth -> init (0x200)
I (2020118) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2020118) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2020118) wifi:state: init -> auth (0xb0)
I (2024478) wifi:state: auth -> init (0x200)
I (2024488) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2024488) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2024488) wifi:state: init -> auth (0xb0)
I (2028848) wifi:state: auth -> init (0x200)
I (2028858) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2028858) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2028858) wifi:state: init -> auth (0xb0)
I (2033218) wifi:state: auth -> init (0x200)
I (2033228) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2033228) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2033228) wifi:state: init -> auth (0xb0)
I (2037588) wifi:state: auth -> init (0x200)
I (2037598) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2037598) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2037598) wifi:state: init -> auth (0xb0)
I (2041958) wifi:state: auth -> init (0x200)
I (2041968) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1, snd_ch_cfg:0x0
I (2041968) ezzle_event_loop: Disconnected from WiFi[/b]1. How can I ensure that ESP32-S3 makes a successful WiFi connection consistently, especially when the WiFi security mode is WPA3-Personal-Transition (presume this is the same as WIFI_AUTH_WPA2_WPA3_PSK?)
2. Why does it take esp_wifi_connect API so many tries to successfully establish connection to the WiFi router?
3. Is there a way of manually increasing the number of retries so the disconnect event isn't triggered after 6 unsuccessful attempts?
I never have this issue with WPA/WPA2_PSK security mode.