Switching from WIFI AP to WiFi STA

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Switching from WIFI AP to WiFi STA

Postby brp80000 » Fri Nov 09, 2018 4:51 am

How can I terminate a local access point and enable access to an external access point?

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);
}
I've tried these sequences to switch

Code: Select all

static void wifi_DEinit(void)
{
	esp_wifi_stop();
	esp_wifi_deinit();
	tcpip_adapter_stop();
}
But I get guru meditation

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Switching from WIFI AP to WiFi STA

Postby brp80000 » Fri Nov 09, 2018 5:40 am

I found an error, both my WIFI functions contained esp_event_loop_init
Now the local AP switches to external.
I still wanted to ask if there is a need to execute commands when switching:
esp_wifi_stop();
esp_wifi_deinit();
tcpip_adapter_stop(WIFI_MODE_AP);

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Switching from WIFI AP to WiFi STA

Postby Ritesh » Fri Nov 09, 2018 7:14 am

brp80000 wrote:I found an error, both my WIFI functions contained esp_event_loop_init
Now the local AP switches to external.
I still wanted to ask if there is a need to execute commands when switching:
esp_wifi_stop();
esp_wifi_deinit();
tcpip_adapter_stop(WIFI_MODE_AP);
Hi,

I believe there is no need to deinit WiFi and stop tcpip adpater to switch from AP to STA and vice versa.

You just needs to stop WiFi and reconfigure it again and then start.

You needs to init WiFi and init TCP IP Adapter only one time while starting WiFi for STA or AP mode.

Let me know if you still have any questions or issue regarding that.
Regards,
Ritesh Prajapati

User avatar
brp80000
Posts: 138
Joined: Thu Oct 04, 2018 7:13 pm

Re: Switching from WIFI AP to WiFi STA

Postby brp80000 » Sun Nov 11, 2018 9:33 am

Ok its work

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Switching from WIFI AP to WiFi STA

Postby Ritesh » Mon Nov 12, 2018 4:42 am

brp80000 wrote:
Sun Nov 11, 2018 9:33 am
Ok its work
Great. Thanks for update. Let me know if any query regarding that into future as well
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: Google [Bot] and 85 guests