diff --git a/components/time/time_manager.c b/components/time/time_manager.c index 521f3f2..bf4a933 100644 --- a/components/time/time_manager.c +++ b/components/time/time_manager.c @@ -77,7 +77,7 @@ static int store_time(void) gettimeofday(&tv, NULL); error = nvs_set_u64(nvs, TIMESTAMP_KEY, tv.tv_sec); if (error == ESP_OK) - ESP_LOGI(TAG, "Stored time"); + ESP_LOGI(TAG, "Time stored"); else ESP_LOGE(TAG, "Error storing time: %04x", error); @@ -92,11 +92,7 @@ static int time_command_func(int argc, char **argv) printf("%02u:%02u\n", time.hour, time.minute); return 0; } else if (argc == 2) { - if (strcmp(argv[1], "sntp-status") == 0) { - const sntp_sync_status_t status = sntp_get_sync_status(); - printf("%s\n", sync_status_description(status)); - return 0; - } else if (strcmp(argv[1], "store") == 0) { + if (strcmp(argv[1], "store") == 0) { return store_time(); } else { Time time; @@ -138,6 +134,32 @@ static int date_command_func(int argc, char **argv) } } +static int sntp_command_func(int argc, char **argv) +{ + if (argc == 2) { + if (strcmp(argv[1], "status") == 0) { + if (esp_sntp_enabled()) { + const sntp_sync_status_t status = sntp_get_sync_status(); + printf("%s\n", sync_status_description(status)); + } else { + printf("Disabled\n"); + } + return 0; + } else if (strcmp(argv[1], "restart") == 0) { + return sntp_restart() ? 0 : 1; + } else if (strcmp(argv[1], "stop") == 0) { + sntp_stop(); + return 0; + } else { + printf("Unrecognised subcommand\n"); + return 1; + } + } else { + printf("Invalid number of arguments\n"); + return 1; + } +} + static void time_saver_func(void *arg) { (void)arg; @@ -165,11 +187,14 @@ void time_manager_init(void) settings_add_sntp_server_callback(&handle_sntp_server_update); console_register( - "time", "Get, set or store the time, or get SNTP status", - "time [HH:MM] OR time ", time_command_func); + "time", "Get, set or store the time", "time [HH:MM] OR time store", + time_command_func); console_register( "date", "Get or set the date", "date [yyyy-mm-dd]", date_command_func); + console_register( + "sntp", "Manage SNTP", "sntp ", + sntp_command_func); // Attempt to load time from storage esp_err_t error;