#include "esp_log.h" #include "esp_netif_sntp.h" #include "esp_sntp.h" #include "obtain_time.h" #include "esp_lvgl_port.h" #include "ihm.h" static const char *TAG = "sntp"; extern lv_subject_t dateHeureSubj; char *days[7]={"Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"}; char *months[12]={"Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"}; void time_sync_notification_cb(struct timeval *tv) { ESP_LOGI(TAG, "Notification of a time synchronization event"); char strftime_buf[64]; // Set timezone to Eastern Standard Time and print local time time_t now; struct tm timeinfo; localtime_r(&now, &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); time(&now); localtime_r(&now, &timeinfo); } void obtain_time() { ESP_LOGI(TAG, "Initializing and starting SNTP"); esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG("pool.ntp.org"); config.sync_cb = time_sync_notification_cb; // Note: This is only needed if we want esp_netif_sntp_init(&config); } void updateTime(void *pvParameter) { char strftime_buf[64]; time_t now = 0; while (1) { time(&now); setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); tzset(); struct tm timeinfo = {0}; localtime_r(&now, &timeinfo); sprintf(strftime_buf, "%s %d %s %02d:%02d", days[timeinfo.tm_wday], timeinfo.tm_mday, months[timeinfo.tm_mon], timeinfo.tm_hour, timeinfo.tm_min); draw_time(strftime_buf); /* lv_obj_refr_size(lv_obj_get_child(lv_obj_get_child(lv_layer_top(),0),0)); lv_obj_refr_size(lv_obj_get_child(lv_layer_top(),0)); lvgl_port_unlock(); }*/ vTaskDelay(60000 / portTICK_PERIOD_MS); } }