add source code that exists so far

This commit is contained in:
Florian Hoss 2022-04-05 20:05:16 +02:00
parent 275c84b48f
commit ef307a24f5
21 changed files with 3276 additions and 0 deletions

View file

@ -0,0 +1,37 @@
#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();
}