Test whether SNTP has updated Time

Is there a way I can test whether SNTP has updated Timer.now() based on server time? I’m trying to save a variable fairly early in the boot process, but only want to do it if the SNTP process has completed (otherwise I’ll set a timer and try again in a few seconds).

In mJS

if( Timer.now() > 1640995200 /* Sat 01 Jan 2022 12:00:00 AM UTC */){
// do something

In C set a flag after the first ntp update

static bool s_time_init = false;

void sntp_time_change_cb(int ev, void* evd, void* arg) {
  const struct mgos_time_changed_arg* ev_data =
    (const struct mgos_time_changed_arg*) (evd);
  LOG(LL_INFO, ("delta: %lf", ev_data->delta));
  if (s_time_init == false) {
    s_time_init = true;
  (void) ev;
  (void) arg;

enum mgos_app_init_result mgos_app_init(void) {
  /* other init actions */
  mgos_event_add_handler(MGOS_EVENT_TIME_CHANGED, sntp_time_change_cb, NULL);


That’s great thanks @nliviu! mJS option is nice and simple, but I prefer the elegance of setting the flag in C - I could then call an FFI function in mJS to get the status of s_time_init.