#include "time_sync.h" #include "esp_sntp.h" #include "esp_log.h" #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" void init_time() { ESP_LOGI("TIME", "Initializing SNTP"); esp_sntp_setoperatingmode(SNTP_OPMODE_POLL); esp_sntp_setservername(0, "pool.ntp.org"); esp_sntp_init(); setenv("TZ", "EET-2EEST,M3.5.0/3,M10.5.0/4", 1); tzset(); time_t now = 0; struct tm timeinfo{}; // ← ВАЖНО int retry = 0; while (timeinfo.tm_year < (2020 - 1900) && retry++ < 10) { ESP_LOGI("TIME", "Waiting for time..."); vTaskDelay(2000 / portTICK_PERIOD_MS); time(&now); localtime_r(&now, &timeinfo); } }