Page 1 of 1

Saving SSID+passwd after WPS procedure.

Posted: Tue Mar 29, 2022 4:42 pm
by bstolk
I am running the WIFI/WPS Example on my ESP32C3U.

While this does get me an IP address, and makes my μcontroller ping-able on my network, I would like to store the result of the WPS on the device (I am using the M5Stack STAMP-C3U μcontroller.)

NOTE: I use the push-button on my router to connect.

Any advice, or example-code on how to make a WPS result permanent, so that it can be reused after power-loss? Does the esp_wps system actually receive the wifi password? Or does it only receive a pin? How can this info be reused?

Re: Saving SSID+passwd after WPS procedure.

Posted: Tue Mar 29, 2022 8:46 pm
by bstolk
Ah, Ok, I managed to do this. You can access credentials (after connecting) as:

Code: Select all

WiFi.SSID();
WiFi.psk();
And I write them to flash, using the SPIFFS interface.

Re: Saving SSID+passwd after WPS procedure.

Posted: Mon Sep 19, 2022 2:21 pm
by toljatyr
or you can use this way:
the SSID and password are stored in the config and given to esp_wifi_set_config, after WPS has finished, you can just use the getter function again by calling

Code: Select all

wifi_config_t config;
esp_err_t err = esp_wifi_get_config(WIFI_IF_STA, &config);
if (err == ESP_OK) {
  printf("SSID: %s, PW: %s\n", (char*) config.sta.ssid, (char*) config.sta.password);
} else {
  printf("Couldn't get config: %d\n", (int) err);
}
and you can then find the SSID and password in that struct again.

Re: Saving SSID+passwd after WPS procedure.

Posted: Tue Jan 03, 2023 2:41 am
by axellin
toljatyr wrote:
Mon Sep 19, 2022 2:21 pm
or you can use this way:
the SSID and password are stored in the config and given to esp_wifi_set_config, after WPS has finished, you can just use the getter function again by calling

Code: Select all

wifi_config_t config;
esp_err_t err = esp_wifi_get_config(WIFI_IF_STA, &config);
if (err == ESP_OK) {
  printf("SSID: %s, PW: %s\n", (char*) config.sta.ssid, (char*) config.sta.password);
} else {
  printf("Couldn't get config: %d\n", (int) err);
}
and you can then find the SSID and password in that struct again.
This no longer work with esp-idf-5.0+ unless you patch the esp-idf by yourself.
https://github.com/espressif/esp-idf/issues/10339