Saving SSID+passwd after WPS procedure.

bstolk
Posts: 23
Joined: Fri Jan 07, 2022 6:44 am

Saving SSID+passwd after WPS procedure.

Postby bstolk » Tue Mar 29, 2022 4:42 pm

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?

bstolk
Posts: 23
Joined: Fri Jan 07, 2022 6:44 am

Re: Saving SSID+passwd after WPS procedure.

Postby bstolk » Tue Mar 29, 2022 8:46 pm

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.

toljatyr
Posts: 13
Joined: Mon Mar 07, 2022 10:39 am

Re: Saving SSID+passwd after WPS procedure.

Postby toljatyr » 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.

axellin
Posts: 199
Joined: Mon Sep 17, 2018 9:09 am

Re: Saving SSID+passwd after WPS procedure.

Postby axellin » Tue Jan 03, 2023 2:41 am

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

Who is online

Users browsing this forum: No registered users and 75 guests