/* WPS example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include #include #include #include "esp_sta.h" #include "esp_system.h" #include "esp_wps.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" static void user_wps_status_cb(int status) { printf("scan status %d\n", status); switch (status) { case WPS_CB_ST_SUCCESS: wifi_wps_disable(); wifi_station_connect(); break; case WPS_CB_ST_FAILED: case WPS_CB_ST_TIMEOUT: wifi_wps_start(); break; } } static void user_wps_start(void) { wifi_wps_disable(); wifi_wps_enable(WPS_TYPE_PBC); wifi_set_wps_cb(user_wps_status_cb); wifi_wps_start(); } /****************************************************************************** * FunctionName : user_rf_cal_sector_set * Description : SDK just reversed 4 sectors, used for rf init data and paramters. * We add this function to force users to set rf cal sector, since * we don't know which sector is free in user's application. * sector map for last several sectors : ABCCC * A : rf cal * B : rf init data * C : sdk parameters * Parameters : none * Returns : rf cal sector *******************************************************************************/ uint32_t user_rf_cal_sector_set(void) { flash_size_map size_map = system_get_flash_size_map(); uint32_t rf_cal_sec = 0; switch (size_map) { case FLASH_SIZE_4M_MAP_256_256: rf_cal_sec = 128 - 5; break; case FLASH_SIZE_8M_MAP_512_512: rf_cal_sec = 256 - 5; break; case FLASH_SIZE_16M_MAP_512_512: case FLASH_SIZE_16M_MAP_1024_1024: rf_cal_sec = 512 - 5; break; case FLASH_SIZE_32M_MAP_512_512: case FLASH_SIZE_32M_MAP_1024_1024: rf_cal_sec = 1024 - 5; break; case FLASH_SIZE_64M_MAP_1024_1024: rf_cal_sec = 2048 - 5; break; case FLASH_SIZE_128M_MAP_1024_1024: rf_cal_sec = 4096 - 5; break; default: rf_cal_sec = 0; break; } return rf_cal_sec; } static void wps_task(void* pvParameters) { wifi_set_opmode(STATION_MODE); user_wps_start(); vTaskDelete(NULL); } void user_init(void) { xTaskCreate(wps_task, "wps_task", 1024, NULL, 4, NULL); }