#include "jannex/jannex.h" #include "jannex/ota.h" #include "jannex/api/console.h" #include #include "esp_log.h" #include "esp_ota_ops.h" #include "esp_event.h" #include "nvs_flash.h" #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_netif.h" #include "esp_netif_sntp.h" #include "esp_sntp.h" void time_sync_notification_cb(struct timeval *tv) { ESP_LOGI(jannexTAG, "Notification of a time synchronization event"); } void initialize_sntp() { ESP_LOGI(jannexTAG, "Initializing SNTP..."); // set timezone to berlin // setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); // tzset(); esp_sntp_config_t config = { .start = true, .sync_cb = time_sync_notification_cb, .smooth_sync = false, .server_from_dhcp = true, // accept NTP offers from DHCP server, if any (need to enable *before* connecting) .renew_servers_after_new_IP = true, // let esp-netif update configured SNTP server(s) after receiving DHCP lease .index_of_first_server = 1, // updates from server num 1, leaving server 0 (from DHCP) intact .num_of_servers = 1, // update only one server .servers = {CONFIG_NTP_SERVER}, // server pool }; /*esp_netif_sntp_init(&config); esp_netif_sntp_start(); // get current time in human readable format and print to log time_t now; struct tm timeinfo; time(&now); localtime_r(&now, &timeinfo); if (!localtime(&timeinfo)) { ESP_LOGE(jannexTAG, "Failed to obtain time"); } else { ESP_LOGI(jannexTAG, "The current date/time in Berlin is: %s", asctime(&timeinfo)); }*/ } void startJannex(void *parameter) { defaultValuesToStorage(); #ifdef WIFI_ENABLED esp_log_level_set("esp-x509-crt-bundle", ESP_LOG_WARN); esp_log_level_set("wifi", ESP_LOG_WARN); init_wifi(); #endif #ifdef WEB_SERVER_ENABLED initServer(); #endif #ifdef CONFIG_HTTP_SERVER_ENABLE_DEBUG_MODE connectConsole(); #endif // CONFIG_HTTP_SERVER_ENABLE_DEBUG_MODE initialize_sntp(); vTaskDelete(NULL); } void initJannex() { initStorage(); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); #ifdef CONFIG_HTTP_SERVER_ENABLE_DEBUG_MODE initConsole(); #endif // CONFIG_HTTP_SERVER_ENABLE_DEBUG_MODE const esp_app_desc_t *app_desc = esp_app_get_description(); ESP_LOGI(jannexTAG, "Initializing Jannex"); ESP_LOGI(jannexTAG, "Current Build version: %s", app_desc->version); ESP_LOGI(jannexTAG, "Current Build name: %s", app_desc->project_name); ESP_LOGI(jannexTAG, "Current Build date: %s", app_desc->date); ESP_LOGI(jannexTAG, "Current Build time: %s", app_desc->time); xTaskCreate(startJannex, "startJannex", 4096, NULL, 5, NULL); xTaskCreate(checkIfOTAwasSuccessful, "checkIfOTAwasSuccessful", 4096, NULL, 5, NULL); } void updateJannex() { xTaskCreate(checkForUpdatesAndInstall, "checkForUpdatesAndInstall", 8192, NULL, 5, NULL); }