- My goal is: I want to start running with the SNTP client turned off and, later, “on-the-fly” (no intervening reboot) turn it on. This is for testing purposes (need to test logic that accumulates events before SNTP gets the time, and then corrects and transmits them after we have received a time update (using the MGOS_EVENT_TIME_CHANGED event to detect that).
- My actions are:
My mos.yml has sntp.enable set to false, and debug.level set to 3. I have this RPC handler:
bool was_enabled = mgos_sys_config_get_sntp_enable();
mgos_sys_config_set_sntp_enable(true);
if (!was_enabled) {
LOG (LL_INFO, ("turning on the SNTP client"));
mgos_sntp_init();
}
mg_rpc_send_responsef(ri, "{enabled: %d}", mgos_sys_config_get_sntp_enable());
- The result I see is: when this RPC is invoked, I see the “turning on the SNTP client”, but the SNTP client does not start (no “mgos_sntp.c:127 SNTP next query in 1040 ms”, no logging of UDP packets to time.google.com by mg_net.c)
I have verified that I would see these in the log if I reboot with sntp.enable=true:
[Jul 23 11:37:50.507] mg_net.c:911 0x3ffc8c08 udp://time.google.com:123 -,-,-
...
[Jul 23 11:37:50.521] mgos_sntp.c:95 SNTP query to time.google.com
[Jul 23 11:37:50.527] mgos_sntp.c:127 SNTP next query in 2196 ms
...
[Jul 23 11:37:50.551] mg_net.c:794 0x3ffc8c08 udp://216.239.35.12:123 -> 0
[Jul 23 11:37:50.556] mgos_sntp.c:48 SNTP sent query to 216.239.35.12
[Jul 23 11:37:50.592] mgos_sntp.c:59 SNTP reply from 216.239.35.12: time 1595518671.429117, local 3.856112, delta 1595518667.573005
[Jul 23 11:37:50.601] mgos_event.c:135 ev MOS3 triggered 2 handlers
[Jul 23 11:37:50.607] mgos_sntp.c:78 SNTP close
[Jul 23 11:37:50.610] mgos_sntp.c:127 SNTP next query in 7275545 ms
- My expectation & question is: I would expect for the SNTP client to begin querying the SNTP server if I call mgos_sys_config_set_sntp_enable(true), then call mgos_sntp_init(). Why doesn’t it?