update project

This commit is contained in:
2026-04-03 23:28:02 +03:00
parent 5e7f26f128
commit 1681a694d3
12 changed files with 191 additions and 83 deletions

28
esp32/main/time_sync.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include "time_sync.h"
#include "esp_sntp.h"
#include "esp_log.h"
#include <time.h>
#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);
}
}