tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.63k stars 1.98k forks source link

Changing STA config's authmode causes the STA config's SSID to become empty #1742

Closed evoon closed 6 months ago

evoon commented 6 months ago

Basic Infos

Hardware

WiFimanager Branch/Release: Master v5.2.1 (I tried v5.2 also)

Esp8266/Esp32: ESP32

Hardware: ESP32-C6-WROOM-1

Description

Wifi_manager STA config's SSID becomes blank after modifying STA config's Authmode, generating an error ESP_ERR_WIFI_SSID on esp_wifi_connect() call.

Sketch

case WM_ORDER_CONNECT_STA:
ESP_LOGI(TAG, "MESSAGE: ORDER_CONNECT_STA");
if((BaseType_t)msg.param == CONNECTION_REQUEST_USER) {
    xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_STA_CONNECT_BIT);
}
else if((BaseType_t)msg.param == CONNECTION_REQUEST_RESTORE_CONNECTION) {
    xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_RESTORE_STA_BIT);
}

uxBits = xEventGroupGetBits(wifi_manager_event_group);
if( ! (uxBits & WIFI_MANAGER_WIFI_CONNECTED_BIT) ){
    wifi_config_t wifi_config;

    ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &wifi_config));

    wifi_config.sta.threshold.authmode = WIFI_AUTH_OPEN;
    wifi_config.sta.threshold.rssi = -99;
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
    if(uxBits & WIFI_MANAGER_SCAN_BIT){
        esp_wifi_scan_stop();
    }
    /* Updating the Wi-Fi protocol chosen by the operator, retrives it from the memory */
    nvs_handle_t my_handle;
    nvs_open("storage", NVS_READWRITE, &my_handle);

    size_t required_size = 0;
    ESP_ERROR_CHECK(nvs_get_str(my_handle, "protocole", NULL, &required_size));
    char *protocol = malloc(required_size);
    ESP_ERROR_CHECK(nvs_get_str(my_handle, "protocole", protocol, &required_size));

    if (strcmp(protocol, "b")==0){
        ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B));
    }
    else if (strcmp(protocol, "g")==0){
        ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G));
    }
    else if (strcmp(protocol, "n")==0){
        ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N));
    }
    else if (strcmp(protocol, "ax")==0){
        ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_11AX));
    }

    nvs_close(my_handle);
    wifi_config_t* printconfig = malloc(sizeof(wifi_config_t));;
    esp_wifi_get_config(ESP_IF_WIFI_STA, printconfig);
    ESP_LOGI(TAG, "wifi_manager_fetch_wifi_sta_config: ssid:%s password:%s",printconfig->sta.ssid,wifi_manager_config_sta->sta.password);
    ESP_LOGI(TAG, "wifi_manager_fetch_wifi_settings: sta_authmode %i",printconfig->sta.threshold.authmode);
    ESP_LOGI(TAG, "wifi_manager_fetch_wifi_settings: RM enabled %i",printconfig->sta.rm_enabled);
    ESP_LOGI(TAG, "wifi_manager_fetch_wifi_settings: BTM enabled %i",printconfig->sta.btm_enabled);
    ESP_LOGI(TAG, "wifi_manager_fetch_wifi_settings: MBO enabled %i",printconfig->sta.mbo_enabled);
    ESP_LOGI(TAG, "wifi_manager_fetch_wifi_settings: FT enabled %i",printconfig->sta.ft_enabled);
    ESP_ERROR_CHECK(esp_wifi_connect());
}

Debug Messages

I (683) wifi_init: rx ba win: 6
I (683) wifi_init: tcpip mbox: 32
I (683) wifi_init: udp mbox: 6
I (683) wifi_init: tcp mbox: 6
I (693) wifi_init: tcp tx win: 5760
I (693) wifi_init: tcp rx win: 5760
I (703) wifi_init: tcp mss: 1440
I (703) wifi_init: WiFi IRAM OP enabled
I (703) wifi_init: WiFi RX IRAM OP enabled
I (1063) phy_init: phy_version 230,c773401,Oct 30 2023,15:07:16
I (1113) wifi_manager: WIFI_EVENT_STA_START
I (1113) http_server: Registering URI handlers
I (1113) wifi_manager: MESSAGE: ORDER_LOAD_AND_RESTORE_STA
I (1113) wifi_manager: No saved wifi found on startup. Starting access point.
I (1123) wifi_manager: MESSAGE: ORDER_START_AP
I (1133) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 10.10.0.1
I (1143) wifi_manager: WIFI_EVENT_AP_START
I (1243) http_server: Registering URI handlers
I (7563) wifi_manager: WIFI_EVENT_AP_STACONNECTED
I (7713) esp_netif_lwip: DHCP server assigned IP to a client, IP is: 10.10.0.2
I (24003) http_server: POST /connect.json
I (24003) http_server: log data received: {"multicast":"239.1.1.1","port":"","protocol":"ax"}
I (24013) http_server: ssid: TestReseau, password: Password1!
I (24013) wifi_manager: MESSAGE: ORDER_CONNECT_STA
I (24023) wifi_manager: wifi_manager_fetch_wifi_sta_config: ssid: password:Password1!
I (24023) wifi_manager: wifi_manager_fetch_wifi_settings: sta_authmode 0
I (24033) wifi_manager: wifi_manager_fetch_wifi_settings: RM enabled 1
I (24043) wifi_manager: wifi_manager_fetch_wifi_settings: BTM enabled 1
I (24053) wifi_manager: wifi_manager_fetch_wifi_settings: MBO enabled 1
I (24053) wifi_manager: wifi_manager_fetch_wifi_settings: FT enabled 1
ESP_ERROR_CHECK failed: esp_err_t 0x300a (ESP_ERR_WIFI_SSID) at 0x4200c3d8
0x4200c3d8: wifi_manager at C:/Users/jesbac/Desktop/STAGE/Projets/esp/softap_prov/components/esp32-wifi-manager/src/wifi_manager.c:1448 (discriminator 1)

file: "./components/esp32-wifi-manager/src/wifi_manager.c" line 1448
func: wifi_manager
expression: esp_wifi_connect()

The thing is that, if I remove the following lines :

wifi_config_t wifi_config;
ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &wifi_config));
wifi_config.sta.threshold.authmode = WIFI_AUTH_OPEN;
wifi_config.sta.threshold.rssi = -99;
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));

And change it to :

ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, wifi_manager_get_wifi_sta_config()));

The SSID is still there and the connexion is successful, I don't get it :(