espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.91k stars 7.09k forks source link

correct usage of esp_wifi_get_config (IDFGH-13140) #14080

Open diplfranzhoepfinger opened 1 week ago

diplfranzhoepfinger commented 1 week ago

Answers checklist.

General issue report

Hi,

how to use esp_wifi_get_config ?

after executing the command, how to know if there was a stored config in flash ?

is this the right way ?

    //Check if Configs are available: 

    esp_wifi_get_config(WIFI_IF_AP, &ap_cfg);
    esp_wifi_get_config(WIFI_IF_STA, &sta_cfg);

    ESP_LOGI(TAG_AP, "wifi_init_softap stored: SSID:%s password:%s channel:%d",
             ap_cfg.ap.ssid, ap_cfg.ap.password, ap_cfg.ap.channel);          

    ESP_LOGI(TAG_STA, "wifi_init_station stored. SSID:%s password:%s channel:%d",
             sta_cfg.sta.ssid, sta_cfg.sta.password, sta_cfg.sta.channel);             
diplfranzhoepfinger commented 1 week ago

also discussed here:

https://esp32.com/viewtopic.php?t=29199

ravinder-bb commented 1 week ago

Yes, that is right way.

Default storage in WIFI_STORAGE_FLASH

You can manually change storage Documentation

esp_wifi_set_storage(WIFI_STORAGE_FLASH);
imdahsiaria90 commented 3 days ago

@diplfranzhoepfinger @ravinder-bb

I am trying to do the same but for me the contents of wifiStaConfig.sta_cfg.sta.ssid and wifiStaConfig.sta_cfg.sta.password are 0 /empty I am using IDF v5.0.1

Example code

     wifi_config_t wifiStaConfig = {0};

    esp_err_t ret = esp_wifi_get_config(ESP_IF_WIFI_AP, &wifiStaConfig);

    printf("WIFI STA SSID DETECTED: %s\n", wifiStaConfig.sta.ssid);
    printf("WIFI STA PASSWORD DETECTED: %s\n", `wifiStaConfig.sta.password);

Any idea what would be wrong ? I have successfully stored it. The reading does not work

mhdong commented 3 days ago

Hi @imdahsiaria90 esp_wifi_get_config(ESP_IF_WIFI_STA, &wifiStaConfig);