[solved] Time synchronization not correct (RTC / timezone)

Currently I get the following information from PC Engines Support Team

The Board does not have DS1307, but the CPU has a built-in clock whitch is kept running by the on-board battery.

I drive down the router 1 and check the battery.

If I put the time zone on the router 2 on UTC then I get the same time as with the router 1. However the current time is 1 hour later.

You might read this:

base-files: sysfixtime: Keep RTC time in UTC timezone

https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=9e8e8b7253e9b91c365a990009febec16fd99f0b;hp=76847c7fc90e53d540aa7946fbbb774c670346f3

You are probably seeing an effect of this commit in the router with the RTC.
Possibly your RTC is not in UTC, so the "-u" option in /etc/init.d/sysfixtime is wrong for you.
You might edit that away from /etc/init.d/sysfixtime and play with the other hwclock options

In any case, that commit message gives some useful command examples to explore with the hwclock command.

hwclock is provided by busybox:


root@router1:~# /sbin/hwclock -h
/sbin/hwclock: unrecognized option: h
BusyBox v1.30.0 () multi-call binary.

Usage: hwclock [-r|--show] [-s|--hctosys] [-w|--systohc] [--systz] [--localtime] [-u|--utc] [-f|--rtc FILE]

Query and set hardware clock (RTC)

        -r      Show hardware clock time
        -s      Set system time from hardware clock
        -w      Set hardware clock from system time
        --systz Set in-kernel timezone, correct system time
                if hardware clock is in local time
        -u      Assume hardware clock is kept in UTC
        --localtime     Assume hardware clock is kept in local time
        -f FILE Use specified device (e.g. /dev/rtc2)

Ps. I do not have a router with RTC, so no concrete help, but pointers to useful info.

1 Like

I've got several APU2C4 and APU3C4 units running FreeBSD and Debian with NTP running on all of them. I haven't seen an issue with any of them. As I recall though, those distros assume that the system clock is in UTC unless otherwise configured and read from / write to the RTC at boot and during shutdown. I suspect that @hnyman is on the right track. (I can't confirm as we're without IP transport at their location right now due to a power outage.)

Keeping UTC in the RTC clock makes good sense. You can first synchronize the router with your browser, and then run hwclock -w -u to set the RTC to UTC time. From then on the assumption that the RTC clock is in UTC will be true, and that might fix the problem.

1 Like

My internal ntp-server Debian Stretch shows me the following.

stefan.harbich@dsme01: ~ $ sudo timedatectl
       Local time: Mon 2019-01-07 20:44:08 CET
   Universal time: Mon 2019-01-07 19:44:08 UTC
         RTC time: Mon 2019-01-07 19:44:08
        Time zone: Europe / Berlin (CET, +0100)
  Network time on: yes
NTP synchronized: yes
  RTC in local TZ: no

The firewall, routers and notebooks get the time information from this server.
I can not synchronize my router 1 in the LUCI WebGui with the browser. When pressing the button "Synchronize with browser" the time remains the same. Although the laptop shows the right time.

Ok, so I see by doing some playing that your router 1 and router 2 have the same time but purely fail to output the time in CET zone on the router 1. Is that correct, can you confirm this? when putting "date -u" on both routers you get the same results plus or minus a few seconds yes?

Also I think from this that your RTC is in localtime and OpenWrt expects it to be in UTC.

If we're right so far, then hwclock -w -u on router 1 should write the current system time to the hwclock in UTC format. After doing this and a reboot, what happens?

1 Like

Yes, both routers show the same time with "date -u". The further changes I do when the women no longer television. For this I have to update the firmware on the router one. Thanks, I think you're right.

Unfortunately, the time remains even after the restart by an hour.

I read times with "hwclock -v" from the router more information. Unfortunately I do not know what else to do?

root@rome01:~# hwclock -v
hwclock from util-linux 2.32
System Time: 1546899368.852253
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1546898022 seconds after 1969
Last calibration done at 1546898022 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2019/01/07 22:16:10
Hw clock time : 2019/01/07 22:16:10 = 1546899370 seconds since 1969
Time since last adjustment is 1348 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2019-01-07 22:16:09.247832+00:00

Something has brought the Kofiguration "hwclock -w -u" on the router 1. If I change the time zone to Europe / Berlin in the LUCI web frontend, the current time will finally be displayed after a reboot. If you change this back to "/ etc / config / sysytem" or in the LUCI web frontend in "UTC", the time is no longer correct after a restart. For whatever reason?

it's very difficult to debug time related things unless you tell us actually what time it really is when you post things :wink: the simultaneous output of

date -u
hwclock -v
and the actual manually entered time in UTC and local time at the time you ran the commands

It sounds like everything is working fine except the "date" program isn't outputting your local berlin time. And then your last post sounds like if you set the TZ in LUCI everything is ok?

The current settings under "Europe / Berlin"
The current right time is right now: 22:14

root@rome01:~# uci show system | grep zone
system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3'
system.@system[0].zonename='Europe/Berlin'
...
root@rome01:~# date
Tue Jan  8 22:14:18 CET 2019
...
root@rome01:~# date -u
Tue Jan  8 21:14:19 UTC 2019
...
root@rome01:~# hwclock -v
hwclock from util-linux 2.32
System Time: 1546982060.485948
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1546981947 seconds after 1969
Last calibration done at 1546981947 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2019/01/08 21:14:21
Hw clock time : 2019/01/08 21:14:21 = 1546982061 seconds since 1969
Time since last adjustment is 114 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2019-01-08 22:14:20.091982+01:00

The current settings under "UTC"
The current right time is right now: 22:29

root@rome01:~# uci show system | grep zone
system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3'
system.@system[0].zonename='UTC'
...
root@rome01:~# date
Tue Jan  8 21:29:46 UTC 2019
...
root@rome01:~# date -u
Tue Jan  8 21:29:47 UTC 2019
...
root@rome01:~# hwclock -v
hwclock from util-linux 2.32
System Time: 1546982988.309261
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1546981947 seconds after 1969
Last calibration done at 1546981947 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2019/01/08 21:29:48
Hw clock time : 2019/01/08 21:29:48 = 1546982988 seconds since 1969
Time since last adjustment is 1041 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2019-01-08 21:29:47.904404+00:00

I think slowly that the battery is broken the board? Because the clock does not accept the changes from "hwclock -u -w"?

This seems to be perfectly fine. Everything is working as it is supposed to. The current UTC time is correct, and the current localtime is correct, and the hardware clock is showing UTC time which is correct.

Am I missing something?

Why is the time under
"zonename =" UTC " incorrect?

It isn't. You said:

Which I take to mean the current local time in Berlin, which means at the time you said that it was 21:29 UTC time.

when you tell your router it is in UTC zone, it displays

which is the correct time in UTC

This looks inconsistent to me and may be the "problem" behind why the output of date is shown in UTC.

On one of my devices, I see

jeff@office:~$ fgrep zone /etc/config/system 
	option timezone 'PST8PDT,M3.2.0,M11.1.0'
jeff@office:~$ date -u && date
Tue Jan  8 22:18:44 UTC 2019
Tue Jan  8 14:18:44 PST 2019
jeff@office:~$ uci show system | grep zone
system.@system[0].timezone='PST8PDT,M3.2.0,M11.1.0'

Here's my result from Router 1.
root@rome01:~# fgrep zone /etc/config/system
option timezone 'CET-1CEST,M3.5.0,M10.5.0/3'
...
root@rome01:~# date -u && date
Tue Jan 8 22:43:40 UTC 2019
Tue Jan 8 22:43:40 UTC 2019
...
root@rome01:~# uci show system | grep zone
system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3'

I think that's a bug?

Which zonename did you cofigure?

No zonename configured -- as a thought, is TZ defined in your environment?

config system
	option hostname '<my hostname>'
	option timezone 'PST8PDT,M3.2.0,M11.1.0'
	option ttylogin '0'
	option log_size '64'
	option urandom_seed '0'

config timeserver 'ntp'
	option enabled '1'
	option enable_server '0'
	list server '0.lede.pool.ntp.org'
	list server '1.lede.pool.ntp.org'
	list server '2.lede.pool.ntp.org'
	list server '3.lede.pool.ntp.org'
[...]