About wifi STA - AP mode

sangk82
Posts: 5
Joined: Wed Mar 13, 2024 6:20 am

About wifi STA - AP mode

Postby sangk82 » Tue Mar 19, 2024 2:06 am

hi,
I am beginner of ESP.
I was trying to use STA-AP mode.

I've understood how to use each mode seperately but I wanna know how to use STA-AP mode

here's a general code I found on internet.

Code: Select all

	// set APSTA mode
      ESP_ERROR_CHECK (esp_wifi_set_mode (WIFI_MODE_APSTA));
      
      	// configure AP_config and STA_config
      wifi_config_t wifi_ap_config = {
        .ap = {
               .ssid = SOFTAP_ESP_SSID,
               .ssid_len = strlen (SOFTAP_ESP_SSID),
               .channel = 1,.password = SOFTAP_ESP_PWD,
               .max_connection = 4,
               .authmode = WIFI_AUTH_WPA2_PSK,
               .pmf_cfg = {
                           .required = true,
                           }
               }
      };
      ESP_ERROR_CHECK (esp_wifi_set_config (WIFI_IF_AP, &wifi_ap_config));
            wifi_config_t wifi_sta_config = {
      };
      strcpy ((char *) wifi_sta_config.sta.ssid, __SSID);
      strcpy ((char *) wifi_sta_config.sta.password, __PWD);
      ESP_ERROR_CHECK (esp_wifi_set_config (ESP_IF_WIFI_STA, &wifi_sta_config));
      
      	// wifi start
      ESP_ERROR_CHECK (esp_wifi_start ());
set mode as APSTA and configure STA and AP each and start wifi.

but I tested
set mode APSTA and configure only one, STA or AP, and start wifi.
it works. but I don't know how and why.
it supposed to be configured STA and AP, but I don't know how it works STA or AP.
and it works exactly I expected.
( i try to make a function that working as AP for opening http server and connecting with wifi as STA )
if I only configured STA or AP, I believe it works only for STA or AP not both.

if there's something I am missing please tell me.

thank you so much.

sangk82
Posts: 5
Joined: Wed Mar 13, 2024 6:20 am

I Found a Reason

Postby sangk82 » Tue Mar 19, 2024 6:27 am

Hi, me again

I think I found a reason.

according to the comments of esp_wifi_set_config(),
the wifi config will be saved on NVS autometically.

that was the reason even tho I skip to put the AP mode config, it remained on NVS.
so it can open the server without setting information.

Thank you

liaifat85
Posts: 139
Joined: Wed Dec 06, 2023 2:46 pm

Re: About wifi STA - AP mode

Postby liaifat85 » Tue Mar 19, 2024 10:54 am

To ensure proper functionality in APSTA mode, you should provide configurations for both the STA and AP settings, even if you only intend to use one of them at a time.

sangk82
Posts: 5
Joined: Wed Mar 13, 2024 6:20 am

Re: About wifi STA - AP mode

Postby sangk82 » Fri Mar 22, 2024 12:17 am

Thank you for answering :)

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 184 guests