WiFi connection loss

jk1886
Posts: 5
Joined: Wed Aug 03, 2022 12:41 pm

WiFi connection loss

Postby jk1886 » Sat Jun 01, 2024 9:46 am

On one of the ESP32-WROOM-32D boards I have, there is a problem with periodic WiFi connection loss. After few hours of operation, wifi enters some strange state: there are no messages on console, esp_wifi_sta_get_ap_info returns status connected, but any network request hangs (http client or ping) and board is not responding to network requests.
I suspect that this board is broken, because the same code works fine on the second board.
Now, I want to detect such state and reboot.
This is my ping code:

Code: Select all

    esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
    ping_config.target_addr = target_addr;
    ping_config.count = 5; // Number of ping requests to send
    esp_ping_callbacks_t cbs = {
        .cb_args = NULL,
        .on_ping_success = ping_results,
        .on_ping_timeout = NULL,
        .on_ping_end = NULL
    };
    esp_ping_handle_t ping;
    esp_ping_new_session(&ping_config, &cbs, &ping);
    esp_ping_start(ping);
    vTaskDelay(pdMS_TO_TICKS(10000));
    esp_ping_stop(ping);
    esp_ping_delete_session(ping);
In case of such failure, this code hangs forever.
CPU and other peripherals are running without problems.
Has someone any idea how to detect such case or how to fix it ?

jk1886
Posts: 5
Joined: Wed Aug 03, 2022 12:41 pm

Re: WiFi connection loss

Postby jk1886 » Thu Jun 13, 2024 11:01 am

It looks, that WiFi connection loss is related to backward time correction, issued by SNTP. Incidentally, SNTP sets wrong time:

I (14405539) main: SNTP time=1073479200

(Wed Jan 07 2004 12:40:00 GMT+0000)

This message is from sntp callback:

Code: Select all

void sntp_callback(struct timeval *_tv)
{
    if( _tv )
    {
        ESP_LOGI( TAG, "SNTP time=%lld", _tv->tv_sec );
    }
}
SNTP is initialized like the following:

Code: Select all

        
        esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
        esp_sntp_setservername(0, Config.ntpserver );
        sntp_set_time_sync_notification_cb(sntp_callback);
        esp_sntp_init();
So few questions:
- why SNTP sets wrong time ?
- how to prevent SNTP from big time corrections ?
- why WiFi stack fails without any error in such case ?
- how to restart WiFi in such case ?

Who is online

Users browsing this forum: Bing [Bot] and 93 guests