// // Created by jedi on 04.11.21. // #include "ntp.h" #include "wifi.h" #ifdef __cplusplus extern "C" { #endif /* Add extras/sntp component to makefile for this include to work */ #include #include #ifdef __cplusplus } #endif #include #define SNTP_SERVERS "0.pool.ntp.org", "1.pool.ntp.org", \ "2.pool.ntp.org", "3.pool.ntp.org" SemaphoreHandle_t time_available_semaphore = nullptr; void sntp_task(void *pvParameters) { const char *servers[] = {SNTP_SERVERS}; (void) pvParameters; while (!uxSemaphoreGetCount(wan_available_semaphore)) { vTaskDelay(2000 / portTICK_PERIOD_MS); } /* Start SNTP */ //printf("Starting SNTP... "); /* SNTP will request an update each 5 minutes */ sntp_set_update_delay(5 * 60000); /* Set GMT+1 zone, daylight savings off */ const struct timezone tz = {1 * 60, 1}; /* SNTP initialization */ sntp_initialize(&tz); /* Servers must be configured right after initialization */ sntp_set_servers(servers, sizeof(servers) / sizeof(char *)); printf("SNTP DONE!\n"); xSemaphoreGive(time_available_semaphore); /* Print date and time each 5 seconds */ vTaskDelete(nullptr); }