I've been using the ESP32 WIFI in SoftAP mode. After some tests I am observing certain clients randomly disconnects and won't be able to connect anymore. Below is a debug when this event occurs:
Code: Select all
I (1683272) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1683272) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1683272) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1693232) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1693242) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1693292) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1703222) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1703222) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1703222) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1713222) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1713222) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1713272) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1723212) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1723212) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1723212) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1733372) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1733372) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1733422) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1743252) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1743252) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1743252) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1753352) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1753352) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1753402) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1773202) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1773202) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1773202) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1783452) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1783452) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
Code: Select all
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
ESP_LOGI(WIFI_TAG, "station "MACSTR" join, AID=%d",
MAC2STR(event->mac), event->aid);
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
ESP_LOGI(WIFI_TAG, "station "MACSTR" leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
void wifi_init_softap(void)
{
esp_netif_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_t* wifiAP = esp_netif_create_default_wifi_ap();
esp_netif_ip_info_t ipInfo;
IP4_ADDR(&ipInfo.ip, 192,168,2,1);
IP4_ADDR(&ipInfo.gw, 192,168,2,1);
IP4_ADDR(&ipInfo.netmask, 255,255,255,0);
esp_netif_dhcps_stop(wifiAP);
esp_netif_set_ip_info(wifiAP, &ipInfo);
esp_netif_dhcps_start(wifiAP);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
wifi_config_t wifi_config = {
.ap = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
.password = EXAMPLE_ESP_WIFI_PASS,
.max_connection = EXAMPLE_MAX_STA_CONN,
.authmode = WIFI_AUTH_WPA_WPA2_PSK
},
};
if (strlen(EXAMPLE_ESP_WIFI_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());
ESP_LOGI(WIFI_TAG, "wifi_init_softap finished. SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
Thanks!