Hello people,
I am facing a trouble that a WiFi connection between PC and ESP32 breaks off once per around minute.
ESP32 is working as access point. Just after disconnection, PC connects automatically again.
Could anybody tell me how to avoid this trouble?
Thank you.
WiFi connection breaks off once per around minute
Re: WiFi connection breaks off once per around minute
Not much to tell you as this is not typical. You would need to share some code.
Re: WiFi connection breaks off once per around minute
Thank you for your reply.
Below is source code and log. Any advice would be appreciated.
Thank you.
void wifi_init_softap()
{
s_wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
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 = {
.beacon_interval = 100,
.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(TAG, "wifi_init_softap finished. SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
void app_main()
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
printf("ERROR: nvs_flash_init()\n");
ret = nvs_flash_erase();
ESP_ERROR_CHECK(ret);
ret = nvs_flash_init();
ESP_ERROR_CHECK(ret);
}
wifi_init_softap();
while (1) vTaskDelay(10 / portTICK_PERIOD_MS);
}
I (952645) wifi: station: e4:a4:71:f5:xx:xx join, AID=1, bgn, 40U
I (952655) wifi softAP: station e4:a4:71:f5:xx:xx join, AID=1
I (952665) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
I (956675) wifi: new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (956675) wifi: station: e4:a4:71:f5:xx:xx join, AID=1, bgn, 40U
I (956695) wifi softAP: station e4:a4:71:f5:xx:xx join, AID=1
I (956705) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
W (1264265) wifi: inactive timer: now=4b57cb5f last_rx_time=3957e25e diff=49ba0, aid[1]e4:a4:71:f5:xx:xx leave
I (1264265) wifi: station: e4:a4:71:f5:xx:xx leave, AID = 1, bss_flags is 134242
I (1264275) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
Below is source code and log. Any advice would be appreciated.
Thank you.
void wifi_init_softap()
{
s_wifi_event_group = xEventGroupCreate();
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
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 = {
.beacon_interval = 100,
.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(TAG, "wifi_init_softap finished. SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
}
void app_main()
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
printf("ERROR: nvs_flash_init()\n");
ret = nvs_flash_erase();
ESP_ERROR_CHECK(ret);
ret = nvs_flash_init();
ESP_ERROR_CHECK(ret);
}
wifi_init_softap();
while (1) vTaskDelay(10 / portTICK_PERIOD_MS);
}
I (952645) wifi: station: e4:a4:71:f5:xx:xx join, AID=1, bgn, 40U
I (952655) wifi softAP: station e4:a4:71:f5:xx:xx join, AID=1
I (952665) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
I (956675) wifi: new:<1,1>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
I (956675) wifi: station: e4:a4:71:f5:xx:xx join, AID=1, bgn, 40U
I (956695) wifi softAP: station e4:a4:71:f5:xx:xx join, AID=1
I (956705) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
W (1264265) wifi: inactive timer: now=4b57cb5f last_rx_time=3957e25e diff=49ba0, aid[1]e4:a4:71:f5:xx:xx leave
I (1264265) wifi: station: e4:a4:71:f5:xx:xx leave, AID = 1, bss_flags is 134242
I (1264275) wifi: new:<1,0>, old:<1,1>, ap:<1,1>, sta:<255,255>, prof:1
Re: WiFi connection breaks off once per around minute
where is your "wifi_event_handler" ?
Re: WiFi connection breaks off once per around minute
Oh, I made mistake.
The code is as below.
Thank you.
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(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(TAG, "station "MACSTR" leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
The code is as below.
Thank you.
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(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(TAG, "station "MACSTR" leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
Re: WiFi connection breaks off once per around minute
SOLVED (maybe)
It seems that it was caused by WiFi client. I used windows PC as WiFi client, in which there were two WiFi application. After deleting one of these, no break occurs.
Thank you.
It seems that it was caused by WiFi client. I used windows PC as WiFi client, in which there were two WiFi application. After deleting one of these, no break occurs.
Thank you.
Who is online
Users browsing this forum: Baidu [Spider] and 73 guests