How to show correct time to user?

Hi All,

At my device, we would like to show local time to user.
Basically, we will fill current time with OSD on video stream.
But, we found the the video stream always show UTC time.

I double check the /etc/config/system, set 'CST-8' to option timezone and reload_config, /etc/TZ is correct. But, video stream still show UTC time.

My questions:

  1. Is there a good way to make sure video stream always show local time instead of UCT time?
  2. Is it possible without restart my video stream and OSD always show correct local time even if I apply new timezone?
  3. Package zoneinfo and /etc/localtime are not good solution for my case? After double check this, /etc/locattime link points to non existing file.

Please help. Thanks.

A bit lost here what is the relation between Openwrt and your video stream?
Can you try to explain a bit more how you believe there is a relation between a time shown in a video stream and your router (openwrt)?

2 Likes

Hi faser,

My device has USB port. We plugin USB camera and use V4L2 to capture video frames. Openwrt already provides mjpg-streamer at WebUI. We add a little bit changes before sending out the video frames, we put timestamp on each jpeg. The timestamp is created by gettimeofday(). Thanks.

What is the output of

uci export system
opkg list-installed | grep zoneinfo
1 Like

Hi Trendy,

Please check. Thanks.

root@OpenWrt:/# uci export system
package system

config system
        option hostname 'OpenWrt'
        option ttylogin '0'
        option log_size '64'
        option urandom_seed '0'
        option timezone 'CST-8'

config timeserver 'ntp'
        option enabled '1'
        option enable_server '0'
        list server 'ntp.pool.com'

root@OpenWrt:/# cat /etc/TZ 
CST-8
root@OpenWrt:/# date -u
Fri Nov  6 00:17:08 UTC 2020
root@OpenWrt:/# date
Fri Nov  6 00:17:09 UTC 2020
root@OpenWrt:/# echo $TZ

root@OpenWrt:/# opkg list-installed | grep zoneinfo
root@OpenWrt:/# 

This is an incorrect NTP server:

# nslookup ntp.pool.com
Server:		127.0.0.1
Address:	127.0.0.1#53

** server can't find ntp.pool.com: NXDOMAIN
** server can't find ntp.pool.com: NXDOMAIN

Revert to the defaults:

uci -q delete system.ntp.server
uci add_list system.ntp.server="0.openwrt.pool.ntp.org"
uci add_list system.ntp.server="1.openwrt.pool.ntp.org"
uci add_list system.ntp.server="2.openwrt.pool.ntp.org"
uci add_list system.ntp.server="3.openwrt.pool.ntp.org"
uci commit system
/etc/init.d/sysntpd restart
1 Like

Hi vgaetera,

Oops, ntp.pool.com is my internal ntp server, it works well.
Anyway, I change ntp server to standard.

root@OpenWrt:/# uci export system
package system

config system
        option hostname 'OpenWrt'
        option ttylogin '0'
        option log_size '64'
        option urandom_seed '0'
        option timezone 'CST-8'

config timeserver 'ntp'
        option enabled '1'
        option enable_server '0'
        list server '0.openwrt.pool.ntp.org'

root@OpenWrt:/# date -u
Fri Nov  6 01:06:41 UTC 2020
root@OpenWrt:/# date
Fri Nov  6 01:06:43 UTC 2020

And, my question still over there. Please check. Thanks.

1 Like

Have you tried 'UTC-6' instead of 'CST-8'?
Or using an entry from the database that would also give you correct DST values?

Hi faser,

  1. The result of UTC-6 is same with CST-8.
root@OpenWrt:/etc/nginx# uci export system
package system

config system
        option hostname 'OpenWrt'
        option ttylogin '0'
        option log_size '64'
        option urandom_seed '0'
        option timezone 'UTC-6'

config timeserver 'ntp'
        option enabled '1'
        option enable_server '0'
        list server '0.openwrt.pool.ntp.org'

root@OpenWrt:/etc/nginx# date -u
Fri Nov  6 01:53:26 UTC 2020
root@OpenWrt:/etc/nginx# date
Fri Nov  6 01:53:28 UTC 2020
  1. Yes, I use zoneinfo. But, we don't want to set zonename in /etc/config/system. We would like to try TZ base first.

Thanks.

Not sure about that, as your earlier opkg command did not show it as installed.

Note that there are two config lines and their usage varies depending of whether you have installed "zoneinfo" packages:

        option timezone 'EET-2EEST,M3.5.0/3,M10.5.0/4'
        option zonename 'Europe/Helsinki'

If

  • zoneinfo packages is not installed (= the usual default), the POSIX compliant timezone string is used by musl libc. /etc/TZ is used as string storage.
  • zoneinfo packages are installed (e.g. zoneinfo-europe for me), the zonename option is used to fetch the info from zoneinfo database files based on zone name. There is no /etc/TZ or /tmp/TZ

If feel that you should set both options, just in case.

A list of the values currently supported by LuCI GUI is shown in https://github.com/openwrt/luci/blob/master/modules/luci-base/luasrc/sys/zoneinfo/tzdata.lua

That shows the combination of values (zonename, timezone string) that can be set to the config file. Note that Musl libc actually parses the options without any knowledge of this table, but the table just shows a summary of the normal zoneinfo contents (and has grabbed POSIX strings from there))

3 Likes

Hi Hnyman,

Sorry, I should say I already use zoneinfo at my device to try.
But, I think it is not suitable to my case.

Basically, I prefer use env TZ to get correct local time.
I think I need to export TZ to each daemons if it needs the local time.

For now, I'm interested on if my daemon can auto apply new TZ env when I apply new timezone to system uci config? Do you have experiences on it?
Thanks a lot.

?????

There is no "env TZ" support in OpenWrt.

There is only support for file based "/etc/TZ" and "/tmp/TZ" file based or full zoneinfo with /etc/localtime.

It is possible that some of your apps support it natively, but the underlying C function library "musl" does not support any "TZ env variable".

gettimeofday function comes from musl C library...
So, your app has no knowledge of environment variables.

3 Likes

Hi hnyman,

What export mean is

root@OpenWrt:/# cat /etc/TZ
CST-8
root@OpenWrt:/# echo $TZ

root@OpenWrt:/# date -u
Fri Nov  6 08:24:48 UTC 2020
root@OpenWrt:/# date 
Fri Nov  6 08:24:49 UTC 2020
root@OpenWrt:/# export TZ=$(cat /etc/TZ)
root@OpenWrt:/# echo $TZ
CST-8
root@OpenWrt:/# date -u
Fri Nov  6 08:25:11 UTC 2020
root@OpenWrt:/# date
Fri Nov  6 16:25:12 CST 2020

And I will check if C function musl support or not on my device. Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.