diff --git a/firmware/fiatlux.c b/firmware/fiatlux.c index 9e3efeb..62b1370 100644 --- a/firmware/fiatlux.c +++ b/firmware/fiatlux.c @@ -1,18 +1,17 @@ +#include +#include +#include +#include + #include "system.h" #include "wifi.h" #include "web.h" #include "mqtt.h" #include "lux.h" -#include -#include -#include -#include -#include -void user_init(void) -{ +void user_init(void) { uart_set_baud(0, 115200); printf("SDK version: %s\n", sdk_system_get_sdk_version()); @@ -27,4 +26,6 @@ void user_init(void) xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL); xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL); + + xTaskCreate(&sntp_task, "sntp_task", 512, NULL, 2, NULL); } diff --git a/firmware/system.c b/firmware/system.c index d190606..1980f62 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -10,7 +10,6 @@ #include #include -#include #include #include #include diff --git a/firmware/wifi.cpp b/firmware/wifi.cpp index 729e71a..39a9083 100644 --- a/firmware/wifi.cpp +++ b/firmware/wifi.cpp @@ -10,11 +10,13 @@ #include #include #include +#include extern "C" { #include #include #include +#include } #include @@ -357,5 +359,22 @@ extern "C" void wifi_task(void *pvParameters) { xSemaphoreGive(wifi_available_semaphore); //monitor loop connection here + vTaskDelete(nullptr); +} + +const char *servers[] = {"0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org"}; +const struct timezone tz = {1 * 60, DST_NONE}; // DST_MET would actually be correct, but the SDK has a bug and doesn't handle it correctly + +extern "C" void sntp_task(void *pvParameters) { + (void) pvParameters; + + while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) { + vTaskDelay(1000 / portTICK_PERIOD_MS); + } + + sntp_set_update_delay(5 * 60000); + sntp_initialize(&tz); + sntp_set_servers(servers, sizeof(servers) / sizeof(char *)); + vTaskDelete(nullptr); } \ No newline at end of file diff --git a/firmware/wifi.h b/firmware/wifi.h index 9fec7da..740ab6b 100644 --- a/firmware/wifi.h +++ b/firmware/wifi.h @@ -16,6 +16,8 @@ extern SemaphoreHandle_t wifi_available_semaphore; void wifi_task(void *pvParameters); +void sntp_task(void *pvParameters); + #ifdef __cplusplus } #endif