This repository has been archived on 2024-10-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
esp-firewall/SourceCode/src/common/theSNTP.c

37 lines
923 B
C

#include "common/theSNTP.h"
static const char *TAG = "SNTP";
void sntp_sync_notification_call_back(struct timeval *tv)
{
ESP_LOGI(TAG, "Time synchronization done");
}
static void initialize_sntp()
{
ESP_LOGI(TAG, "Initializing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_set_time_sync_notification_cb(sntp_sync_notification_call_back);
sntp_init();
ESP_LOGI(TAG, "Getting current time from \"%s\"", sntp_getservername(0));
}
static void set_time_zone_to_germany()
{
// Timezone Codes: https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
time_t now;
struct tm timeinfo;
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);
tzset();
time(&now);
localtime_r(&now, &timeinfo);
ESP_LOGI(TAG, "Timezone set to Europe/Berlin");
}
void setup_sntp()
{
set_time_zone_to_germany();
initialize_sntp();
}