Time zone not sync when first booting

Hello everyone, I just beginner of Mongoose OS.

I have some trouble with GitHub - mamuesp/timezones: A Mongoose-OS library which will set the cryptic 'sys.tz_spec' from a human readable notation.

I change timezone by mos tools. And check the config. It already access to config structure. After WiFi and SNTP connected. The current times sync to a previous timezone. I have to push hardware reset. So,The current times will sync to the lastest timezone that I set. How could I solve this trouble.

Thanks so much for reply and sorry for my english.

AFAIK, TZ is read on boot so yes, you have to reboot.

1 Like

Even though CPU is auto reboot after set config by mos tools. TZ is read at first reboot. I have to reboot again.Right?

In conclusion,CPU have to reboot twice.

Question is why I has to reboot twice

Here is the step

  1. Change TZ via mos tool then software reboot . Check!
  2. After Boot TZ has been update and display on DEBUG console. Check!
  3. But time (Clock) is not update still the old one ??? Why
  4. I have to do Hardware Reboot then the Clock now correct with new TZ

I can’t reproduce.
First run after flash:

[Sep 22 12:01:45.681] esp32_wifi.c:539        WiFi AP IP: 192.168.4.1/255.255.255.0 gw 192.168.4.1, DHCP range 192.168.4.2 - 192.168.4.100
[Sep 22 12:01:45.687] mgos_http_server.c:377  HTTP server started on [80]
[Sep 22 12:01:45.687] mgos_rpc_channel_ua:326 0x3ffc9c84 UART0
[Sep 22 12:01:45.984] mgos_sys_config.c:174   Saved to conf9.json
[Sep 22 12:01:45.990] mgos_timezones.c:100    Saving configuration: <no error>
[Sep 22 12:01:46.000] mgos_timezones.c:101    Timezone result for <Europe/Bucharest> from JSON data: <EET-2EEST,M3.5.0/3,M10.5.0/4> ...
[Sep 22 12:01:46.007] mgos_init.c:36          Init done, RAM: 280000 total, 219432 free, 214008 min free
[Sep 22 12:01:46.019] main.c:32               Tock uptime: 1.90, heap total/free/min_free: 279996/219552/214008, now: 1970-01-01T00:00:01
[Sep 22 12:01:46.025] mgos_ota_core.c:1590    UID: 0f980401f0dd02f7, license: none
[Sep 22 12:01:55.122] main.c:32               Tick uptime: 11.00, heap total/free/min_free: 279984/219340/214008, now: 1970-01-01T00:00:11

After wifi setup:

[Sep 22 12:04:19.059] mgos_sntp.c:64          SNTP reply from 216.239.35.12: time 1632301460.015432, local 1632301459.997811, delta 0.017621
[Sep 22 12:04:24.966] main.c:32               Tick uptime: 11.00, heap total/free/min_free: 279900/220588/216168, now: 2021-09-22T12:04:25
1 Like

It would probably help if you provide an example with your code and your log

1 Like

1.My code

  time_t t = time(NULL);
  struct tm tm = *localtime(&t);
  LOG(LL_INFO, ("##Year : %d",tm.tm_year + 1900));
  LOG(LL_INFO, ("##Month: %02d",tm.tm_mon + 1));
  LOG(LL_INFO, ("##Day  : %02d",tm.tm_mday));
  LOG(LL_INFO, ("##Hour : %02d",tm.tm_hour));
  LOG(LL_INFO, ("##Min  : %02d",tm.tm_min));
  LOG(LL_INFO, ("##Sec  : %02d",tm.tm_sec));
  1. Logs after set TZ to Asia/Bangkok by mos tools and after software reset.
    2.1
    2.2
[Sep 23 11:19:53.512] mgos_deps_init.c:595    Init zip-tools 0.1 (86c413b05916f27b75172966aff51e7c78672a2b)...
[Sep 23 11:19:53.512] mgos_deps_init.c:595    Init timezones 0.2 (afeab05eaa81fb2354bc02f8a1840dffb334adc2)...
[Sep 23 11:19:53.512] mgos_timezones.c:121    Timezone init - checking for key ...
[Sep 23 11:19:53.512] mgos_timezones.c:128    Timezone init - olson: <Asia/Bangkok>
[Sep 23 11:19:53.512] mgos_timezones.c:131    Timezone init - dataPath: <>
[Sep 23 11:19:53.512] mgos_timezones.c:133    Timezone init - archFile: <tz-archive.zip>
[Sep 23 11:19:53.512] mgos_timezones.c:135    Timezone init - groupFile: <asia-tz.min.json>
  1. After sync TZ. Actually current times must be 11.26 AM.
[Sep 23 11:26:07.963] main.cpp:837            WiFi STA connected 0x0
[Sep 23 11:26:07.963] mgos_event.c:135        ev WFI2 triggered 1 handlers
[Sep 23 11:26:07.963] mgos_wifi_sta.c:422     State 7 ev 1464224003 timeout 0
[Sep 23 11:26:07.963] main.cpp:840            WiFi STA IP acquired 0x0
[Sep 23 11:26:07.963] mgos_event.c:135        ev WFI3 triggered 1 handlers
[Sep 23 11:26:07.963] mgos_net.c:93           WiFi STA: connected
[Sep 23 11:26:07.963] main.cpp:810            Net connected
[Sep 23 11:26:07.963] mgos_event.c:135        ev NET2 triggered 4 handlers
[Sep 23 11:26:07.963] main.cpp:393            ##Year : 2021
[Sep 23 11:26:07.963] main.cpp:394            ##Month: 09
[Sep 23 11:26:07.963] main.cpp:395            ##Day  : 23
[Sep 23 11:26:07.963] main.cpp:396            ##Hour : 00
[Sep 23 11:26:07.963] main.cpp:397            ##Min  : 26
[Sep 23 11:26:07.963] main.cpp:398            ##Sec  : 07
  1. Log after hardware reset and sync TZ. Current times is correct.
[Sep 23 11:27:59.132] mgos_sntp.c:64          SNTP reply from 216.239.35.4: time 1632371279.526521, local 21.757706, delta 1632371257.768815
[Sep 23 11:27:59.132] mgos_event.c:135        ev MOS3 triggered 3 handlers
[Sep 23 11:27:59.132] mgos_sntp.c:146         SNTP next query in 7278890 ms
[Sep 23 11:27:59.132] main.cpp:393            ##Year : 2021
[Sep 23 11:27:59.132] main.cpp:394            ##Month: 09
[Sep 23 11:27:59.132] main.cpp:395            ##Day  : 23
[Sep 23 11:27:59.132] main.cpp:396            ##Hour : 11
[Sep 23 11:27:59.132] main.cpp:397            ##Min  : 27
[Sep 23 11:27:59.132] main.cpp:398            ##Sec  : 59

Ok, now I understand your scenario.

After the first run, the timezone is set to UTC. Then you change it to Asia/Bangkok, but it is not applied before the next reboot because the timezone is set very early in the boot process.

You can add this in your code to apply it.

1 Like

Excellent! It can solve.
I really want to thank you for your help. :smiley:

Thank you for your help. :smiley: