/* * SPDX-FileCopyrightText: 2022 Helmut Pozimski * * SPDX-License-Identifier: GPL-2.0-only */ #include #include #include "ds3231.h" #define TAG "sntp" static void time_sync_callback(struct timeval *tv) { struct tm date_time; localtime_r(&tv->tv_sec, &date_time); ds3231_write_date_time(date_time); } void sntp_start(uint32_t sync_interval) { sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, "pool.ntp.org"); sntp_set_time_sync_notification_cb(time_sync_callback); sntp_init(); sntp_set_sync_interval(sync_interval); } void await_sntp_sync() { while (sntp_get_sync_status() == SNTP_SYNC_STATUS_RESET) { ESP_LOGI(TAG, "Waiting for system time to be set..."); vTaskDelay(2000 / portTICK_PERIOD_MS); } }