Scenario:
I have an ESP32 that will be a "server" that connects to the Internet as an STA and also as a AP, hence it is setup as APSTA. Several clients ESP32s connect to the "server" and send UDP packets.
Problem:
When the Server is able to connect to the external AP there is NO problem. STA is connected to the assigned AP and the ESP32 AP section assigns IPs and receives UDP packets from the clients.
But if the Server(as an STA) can not connect to the external AP, the local AP section takes a very long time to assign an IP to its clients and receives UDP packets after a very long time (if at all), missing many UDP packets sent and. One can see that the client is waiting for the IP with the ESP_LOG at Info level.
Reasoning:
It seems that the STA keeps trying to connect to its configured SSID and causes a SERIOUS bottleneck that eats the wifi's response time and/or cpu (really don't know this). Probably its "scanning" and this is hurting the overall process.
Proof of Reasoning:
(a) When STA connects to the external AP from the start everything flows as expected.
(b) When the STA connects to the external AP some time after start work begins flowing normally. Meanwhile there is serious bottleneck which could imply that the STA is trying to connect to the external AP and eating cycles and hurting everything wifi related.
(c) If I do not configure the STA section,
Code: Select all
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &configap));
(c1) This would mean the ESP is NOT trying to connect to the external AP and hence does not eat cpu cycles or wifi process.
(d) This was proved by commenting out the STA config section
The WiFi init section is this
Code: Select all
void initWiFi()
{
wifi_init_config_t cfg=WIFI_INIT_CONFIG_DEFAULT();
wifi_config_t configap;
u8 mac[6];
char textl[20];
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(wifi_event_handler, NULL));
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
esp_wifi_set_ps(WIFI_PS_NONE); //otherwise multicast does not work well or at all
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
esp_wifi_get_mac(ESP_IF_WIFI_STA, (uint8_t*)&mac);
memset(&configap,0,sizeof(configap));
if(sysConfig.ssid[1][0])!=0) //SSID for external AP and internet access
{
strcpy((char *)configap.sta.ssid , sysConfig.ssid[1]);
strcpy((char *)configap.sta.password, sysConfig.pass[1]);
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &configap));
}
if(sysConfig.ssid[0][0])!=0) //ssid for local AP
{
strcpy((char *)configap.ap.ssid,sysConfig.ssid[0]);
strcpy((char *)configap.ap.password,sysConfig.pass[0]);
printf("AP Loading [%s][%s]\n",configap.ap.ssid,configap.ap.password);
}
else
{ //no name given yet, assign one
sprintf(textl,"LightIoT%02x%02x",mac[4],mac[5]);
strcpy((char*)configap.ap.ssid,textl);
strcpy((char*)configap.ap.password,textl);
}
configap.ap.ssid_len=strlen((char *)configap.ap.ssid);
configap.ap.authmode=WIFI_AUTH_WPA_PSK;
configap.ap.ssid_hidden=false;
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &configap));
ESP_ERROR_CHECK(esp_wifi_start());
}
Is this a bug? Is there a way around this problem?
Any help welcomed.
Comments:
I believe this a rather standard situation and unless I've made programming errors, it should not happen AT ALL. During normal operations an internet access can and will go down and what is going to happed is unpredictable. This makes the ESP an unreliable alternative for time critical solutions.
What's been tested:
Changed many of the config options for the Ap and the STA with no change
beacon interval,
scan option,
listen interval,
Regards.