Add 'sntp ip' command for getting SNTP server's IP

Useful for testing server resolution
This commit is contained in:
Camden Dixie O'Brien 2023-05-19 18:13:08 +01:00
parent ba1fe7239e
commit fc74ff84ce

View File

@ -60,6 +60,10 @@ static int command_func(int argc, char **argv)
} else if (strcmp(argv[1], "stop") == 0) {
sntp_stop();
return 0;
} else if (strcmp(argv[1], "ip") == 0) {
const ip_addr_t *ip = esp_sntp_getserver(0);
printf("%s\n", ipaddr_ntoa(ip));
return 0;
} else {
printf("Unrecognised subcommand\n");
return 1;
@ -76,14 +80,15 @@ void time_sntp_init(void)
(void)settings_get_sntp_server(sntp_server, SETTINGS_MAX_VALUE_SIZE);
settings_add_sntp_server_callback(&handle_sntp_server_update);
esp_sntp_set_sync_mode(SNTP_SYNC_MODE_SMOOTH);
esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL);
esp_sntp_setservername(0, sntp_server);
sntp_set_time_sync_notification_cb(sntp_sync_callback);
esp_sntp_init();
sntp_set_time_sync_notification_cb(sntp_sync_callback);
console_register(
"sntp", "Manage SNTP", "sntp <status|restart|stop>", command_func);
"sntp", "Manage SNTP", "sntp <status|restart|stop|ip>",
command_func);
}
void time_sntp_restart(void)