Merge branch 'feature/module-config' into main (resolved conflicts)
Some checks failed
Build / idf-build (push) Has been cancelled

This commit is contained in:
2026-04-03 20:17:40 +08:00
17 changed files with 1053 additions and 31 deletions

View File

@@ -13,6 +13,7 @@
#include "cron/cron_service.h"
#include "heartbeat/heartbeat.h"
#include "skills/skill_loader.h"
#include "time_sync/time_sync.h"
#include <string.h>
#include <stdio.h>
@@ -733,8 +734,8 @@ static int cmd_set_timezone(int argc, char **argv)
return 0;
}
/* --- timezone_show command --- */
static int cmd_timezone_show(int argc, char **argv)
/* --- ntp_status command --- */
static int cmd_ntp_status(int argc, char **argv)
{
(void)argc;
(void)argv;
@@ -761,6 +762,68 @@ static int cmd_timezone_show(int argc, char **argv)
char time_str[64];
strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S %Z (%A)", &tm_now);
printf("Local time: %s\n", time_str);
printf("Time sync: %s\n", time_sync_status_str());
printf("NTP server: %s\n", time_sync_get_server());
char synced_str[32];
if (time_sync_get_last_synced(synced_str, sizeof(synced_str))) {
printf("Last synced: %s\n", synced_str);
} else {
printf("Last synced: never\n");
}
return 0;
}
/* --- ntp_sync command --- */
static int cmd_ntp_sync(int argc, char **argv)
{
(void)argc;
(void)argv;
if (time_sync_is_synced()) {
printf("Time is already synced. Use 'ntp_set <server>' to change server.\n");
return 0;
}
printf("Triggering SNTP sync...\n");
time_sync_restart();
vTaskDelay(pdMS_TO_TICKS(2000));
if (time_sync_is_synced()) {
char synced_str[32];
time_sync_get_last_synced(synced_str, sizeof(synced_str));
printf("Synced successfully. Last synced: %s\n", synced_str);
} else {
printf("Sync in progress. Check 'ntp_status' for updates.\n");
}
return 0;
}
/* --- ntp_set command --- */
typedef struct {
struct arg_str *server;
struct arg_end *end;
} ntp_set_args;
static ntp_set_args ntp_set_arguments;
static int cmd_ntp_set(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **)&ntp_set_arguments);
if (nerrors != 0) {
arg_print_errors(stderr, ntp_set_arguments.end, argv[0]);
printf("Usage: ntp_set <server>\n");
return 1;
}
const char *server = ntp_set_arguments.server->sval[0];
esp_err_t err = time_sync_set_server(server);
if (err != ESP_OK) {
printf("Failed to set NTP server: %s\n", esp_err_to_name(err));
return 1;
}
printf("NTP server set to '%s'. Restart or run 'ntp_sync' to apply.\n", server);
return 0;
}
@@ -1288,13 +1351,32 @@ esp_err_t serial_cli_init(void)
};
esp_console_cmd_register(&set_timezone_cmd);
/* timezone_show */
esp_console_cmd_t timezone_show_cmd = {
.command = "timezone_show",
.help = "Show current timezone and local time",
.func = &cmd_timezone_show,
/* ntp_status */
esp_console_cmd_t ntp_status_cmd = {
.command = "ntp_status",
.help = "Show timezone, local time, NTP sync status, server and last sync time",
.func = &cmd_ntp_status,
};
esp_console_cmd_register(&timezone_show_cmd);
esp_console_cmd_register(&ntp_status_cmd);
/* ntp_sync */
esp_console_cmd_t ntp_sync_cmd = {
.command = "ntp_sync",
.help = "Manually trigger NTP time synchronization",
.func = &cmd_ntp_sync,
};
esp_console_cmd_register(&ntp_sync_cmd);
/* ntp_set */
ntp_set_arguments.server = arg_str1(NULL, NULL, "<server>", "NTP server hostname");
ntp_set_arguments.end = arg_end(1);
esp_console_cmd_t ntp_set_cmd = {
.command = "ntp_set",
.help = "Set custom NTP server (e.g. ntp_set ntp.ntsc.ac.cn)",
.func = &cmd_ntp_set,
.argtable = &ntp_set_arguments,
};
esp_console_cmd_register(&ntp_set_cmd);
/* heartbeat_trigger */
esp_console_cmd_t heartbeat_cmd = {