I am working on ESP32-IDF 2.0 RC1 RTOS SDK and I want to enable and start WPS mode into Station Mode. I have written some cdoe but not sure it will be worked or not.
Please find following code to start WPS mode.
Code: Select all
void WifiInIt()
{
esp_err_t error_code = 0;
tcpip_adapter_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_FLASH) );
/// Added for WPS support only
error_code = esp_wifi_set_mode(WIFI_MODE_STA);
if(error_code)
{
printf("esp_wifi_set_mode is failed to execute...\n");
}
else
{
printf("esp_wifi_set_mode is executed successfully...\n");
}
/// End edit
}
Code: Select all
int app_main(void)
{
esp_err_t error_code = 0;
nvs_flash_init();
WifiInIt();
/// Added code to check WPS support only
//error_code = esp_wifi_wps_enable(WPS_TYPE_PIN); /// WPS PIN Configuration Type
error_code = esp_wifi_wps_enable(WPS_TYPE_PBC); /// WPS PBC (Push Button Configuration) Type
if(error_code)
{
printf("esp_wifi_wps_enable is failed to execute...\n");
}
else
{
printf("esp_wifi_wps_enable is executed successfully...\n");
Delay(5000);
/* 120 milliseconds blocking time*/
error_code = esp_wifi_wps_start(120);
if(error_code)
{
printf("esp_wifi_wps_start is failed to execute...\n");
}
else
{
printf("esp_wifi_wps_start is executed successfully...\n");
}
Delay(5000);
}
/// End edit
return 0;
}