WIFI_MODE_APSTA Sample

fischershaw
Posts: 2
Joined: Mon Nov 21, 2016 3:34 am

WIFI_MODE_APSTA Sample

Postby fischershaw » Mon Nov 21, 2016 3:38 am

Will there be a sample using WIFI_MODE_APSTA?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WIFI_MODE_APSTA Sample

Postby kolban » Mon Nov 21, 2016 2:37 pm

Howdy,
What would you like to see as a sample? If you loosely thing of the ESP32 as having two distinct network interfaces ... one for connecting to an access point (the ESP32 being a station) and the other for being an access point, then you pretty much have it. What are you hoping to see in a sample that has an ESP32 being both a station and an access point?

By knowing what you'd like to see, that would give the community some guidance on what a sample should actually "do".
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

fischershaw
Posts: 2
Joined: Mon Nov 21, 2016 3:34 am

Re: WIFI_MODE_APSTA Sample

Postby fischershaw » Fri Nov 25, 2016 8:01 pm

Sorry, got distracted with another project. So I am guessing that when esp_wifi_set_mode(WIFI_MODE_APSTA) has been selected, then esp_wifi_set_config() is used separately on each interface, once with WIFI_IF_STA and once with WIFI_IF_AP.

Why would one not just always select WIFI_MODE_APSTA and subsequently configure whichever interface(s) is actually used? Does it consume additional resources or cause other limitations?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WIFI_MODE_APSTA Sample

Postby kolban » Sat Nov 26, 2016 3:25 am

Its possible that during execution, one wants to dynamically start and stop being either an access point, a station or both. I would presume that setting the mode will dynamically switch off/on any of the other modes of operation not included.

So for example, I might initially want to be an access point to get configuration information and then, once configured become a station to the access point that was dynamically selected. At that time I might want to stop being an access point.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: WIFI_MODE_APSTA Sample

Postby ESP_igrr » Sat Nov 26, 2016 5:21 am

Enabling AP when not actually using it may be a bad idea for the following reasons:
1. When AP is enabled, modem sleep mode can not be used, causing higher power consumption,
2. When AP mode is enabled, extra memory is allocated for the AP control block.

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: WIFI_MODE_APSTA Sample

Postby imtiaz » Thu Jan 26, 2017 12:34 am

Hi All,

I have been trying to setup APSTA mode without success , can anyone spot a problem. I am bit confused by this API - what should I set
esp_wifi_set_config(WIFI_IF_AP, &wifi_config) to in this case as there is no option for APSTA mode.
#define AP_EXAMPLE_WIFI_SSID "IMTIAZ\0"
#define AP_EXAMPLE_WIFI_PASS "12345678"

#define STA_EXAMPLE_WIFI_SSID "Syrp_Wireless"
#define STA_EXAMPLE_WIFI_PASS "87654321"
static void initialise_wifi(void)
{
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_RAM) );
wifi_config_t wifi_config = {
.sta ={
.ssid = STA_EXAMPLE_WIFI_SSID,
.password = STA_EXAMPLE_WIFI_PASS,

},
.ap = {
.ssid = AP_EXAMPLE_WIFI_SSID,
.ssid_len = 0,
.password = AP_EXAMPLE_WIFI_PASS,
.channel = 1,
.authmode = WIFI_AUTH_WPA2_PSK,
.beacon_interval = 400,
.max_connection = 16,
}
};

ESP_LOGI(TAG, "Setting WiFi AP: SSID %s", wifi_config.ap.ssid);
ESP_LOGI(TAG, " Pass %s", wifi_config.ap.password);
ESP_LOGI(TAG, "Setting WiFi STA: SSID %s", wifi_config.sta.ssid);
ESP_LOGI(TAG, " Pass %s", wifi_config.sta.password);

ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_APSTA) );
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &wifi_config) );
//ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_start());
}

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WIFI_MODE_APSTA Sample

Postby kolban » Thu Jan 26, 2017 1:14 am

Call esp_wifi_set_config() twice. Once for the settings for the station interface and a second time with the settings for the access point interface.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: WIFI_MODE_APSTA Sample

Postby imtiaz » Thu Jan 26, 2017 1:39 am

Oh - you've got be kidding me, this is union:
typedef union {
wifi_ap_config_t ap; /**< configuration of AP */
wifi_sta_config_t sta; /**< configuration of STA */
} wifi_config_t;

I dont get why its done like this - super confusing. I didnt notice this - I assumed its a struct.. I'll try again.

Thanks

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WIFI_MODE_APSTA Sample

Postby kolban » Thu Jan 26, 2017 4:17 am

My opinion ... its a design choice ... the designers said to themselves (I guess) ... we need to provide an API to configure WiFi ... oh wait ... there are TWO WiFi interfaces on an ESP32 ... one for the station interface and one for the access point interface. Both interfaces need distinct parameters ... so ... we either provide two interfaces ... eg. esp_config_wifi_ap() and esp_config_wifi_sta() or we provide one interface esp_config_wifi() which takes as a parameter which interface to configure ... oh ... but now we need to pass in one of two distinct data type structure ... I know ... we'll union them.

I'm not sure that there is a correct answer to design choices. If one goes with the choice of a single API with two distinct parameter sets then the union structure seems to make sense.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: WIFI_MODE_APSTA Sample

Postby imtiaz » Thu Jan 26, 2017 6:25 pm

Yeah I understand the reasoning - however the API should have better documentation so you dont have to figure these things out the hard way or by trial and error.

On a positive note I've got it to work in APSTA mode - finally

Who is online

Users browsing this forum: No registered users and 92 guests