Hi everyone,
I am developing a project with wroom32. I tried to use the WPS example, but got an error for “wifi_event_sta_wps_er_success_t” because it is not defined.
Searching the web, I found that it is a feature of version 4.2. So is there a workaround for version 4.1? Or when v4.2 will be available on platformio?
Thanks.
Are you sure you can’t just use the WPS example intended for the version PlatformIO uses (4.1), at esp-idf/examples/wifi/wps at v4.1 · espressif/esp-idf · GitHub ?
This issue is already tracked in Add support for ESP-IDF v4.2 · Issue #455 · platformio/platform-espressif32 · GitHub , but no developer has responded yet.
I need to know the connection’s SSID and password. With the 4.1 example those informations aren’t available. Or there is another way to get it with 4.1 idf version using WPS?
Well technically since the WPS code does
if (sm->ap_cred_cnt == 1) {
memset(config, 0x00, sizeof(wifi_sta_config_t));
memcpy(config->sta.ssid, sm->ssid[0], sm->ssid_len[0]);
memcpy(config->sta.password, sm->key[0], sm->key_len[0]);
memcpy(config->sta.bssid, sm->bssid, ETH_ALEN);
config->sta.bssid_set = 0;
esp_wifi_set_config(0, config);
So 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
/**
* @brief Get configuration of specified interface
*
* @param interface interface
* @param[out] conf station or soft-AP configuration
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_ERR_WIFI_IF: invalid interface
*/
esp_err_t esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf);
so by e.g. calling
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.
typedef struct {
uint8_t ssid[32]; /**< SSID of target AP. */
uint8_t password[64]; /**< Password of target AP. */
wifi_scan_method_t scan_method; /**< do all channel scan or fast scan */
bool bssid_set; /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
uint8_t bssid[6]; /**< MAC address of target AP*/
uint8_t channel; /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
uint16_t listen_interval; /**< Listen interval for ESP32 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0. */
wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */
wifi_scan_threshold_t threshold; /**< When sort_method is set, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame. Will be advertized in RSN Capabilities in RSN IE. */
uint32_t rm_enabled:1; /**< Whether Radio Measurements are enabled for the connection */
uint32_t btm_enabled:1; /**< Whether BSS Transition Management is enabled for the connection */
uint32_t reserved:30; /**< Reserved for future feature set */
} wifi_sta_config_t;
/** @brief Configuration data for ESP32 AP or STA.
*
* The usage of this union (for ap or sta configuration) is determined by the accompanying
* interface argument passed to esp_wifi_set_config() or esp_wifi_get_config()
This file has been truncated. show original
Caveat is that ESP-IDF v4.1 only seems to work when the WPS procedure returns 1 SSID and password, not multiple ones. For that an update to v4.2 must be awaited.
Thank you for your help. I’m going to try your solution.