This commit is contained in:
2021-03-10 10:07:11 +01:00
parent 08641b74ea
commit 1e8eac5d22
5 changed files with 54 additions and 1 deletions

29
src/main/timesync.c Normal file
View File

@ -0,0 +1,29 @@
#include "timesync.h>"
#include <stdbool.h>
#include <esp_log.h>
#include <esp_sntp.h>
#include <time.h>
#include <sys/time.h>
static const char *TAG = "ts";
static bool synchronized = false;
void timesyncCallback(struct timeval *tv) {
ESP_LOGI(TAG, "time is synchronized now");
synchronized = true;
}
void timesyncInit() {
ESP_LOGI(TAG, "Initializiing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, SNTP_SERVER);
sntp_set_time_sync_notification_cb(timesyncCallback);
sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED);
sntp_set_sync_interval(60*1000); // 1 minute
sntp_init();
}
bool timesyncReady() {
return synchronized;
}