Switching from WIFI AP to WiFi STA
Posted: Fri Nov 09, 2018 4:51 am
How can I terminate a local access point and enable access to an external access point?
I've tried these sequences to switch
But I get guru meditation
Code: Select all
static void wifi_init_STA(void)
{
wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler2, 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_RAM) );
wifi_config_t wifi_config = {
.sta = {
.ssid = EXT_SSID,
.password = EXT_PASS,},
};
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_start() );
printf("wifi_init_STA finished.SSID:%s password:%s\n", wifi_config.sta.ssid, wifi_config.sta.password);
}
void wifi_init_softAP()
{
wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler1, NULL));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
.ap = {
.ssid = AP_SSID,
.ssid_len = strlen(AP_SSID),
.password = AP_PASS,
.max_connection = 1,
.authmode = WIFI_AUTH_WPA_WPA2_PSK},
};
if (strlen(AP_PASS) == 0){
wifi_config.ap.authmode = WIFI_AUTH_OPEN; }
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
printf("wifi_init_softAP finished.SSID:%s password:%s \n", AP_SSID, AP_PASS);
}
Code: Select all
static void wifi_DEinit(void)
{
esp_wifi_stop();
esp_wifi_deinit();
tcpip_adapter_stop();
}