1 2 3 Previous Next 39 Replies Latest reply on Sep 5, 2016 5:34 AM by javilez

    Setting time zone and synchronizing time with time server on Edison

    vjou

      I have been trying to set the time zone and synchronize time with time server on Edison. It took time to gather information. So, posting what I did may help newbies like me. Or, for my record, at least.

       

      1. Setting time zone

      Originally, /etc/localtime is linked to /usr/share/zoneinfo/Universal. This seems UTC.

      root@Edison:~# ls -l /etc/localtime
      lrwxrwxrwx    1 root     root            29 Sep  8 12:22 /etc/localtime -> /usr/share/zoneinfo/Universal

      I looked for my time zone and found it under /usr/share/zoneinfo/America/

      root@Edison:~# ls -l /usr/share/zoneinfo/America/
      -rw-r--r--    1 root     root          2358 Sep  3 19:39 Anchorage
      -rw-r--r--    1 root     root           240 Sep  3 19:39 Caracas
      -rw-r--r--    1 root     root          3559 Sep  3 19:39 Chicago
      -rw-r--r--    1 root     root          2427 Sep  3 19:39 Denver
      -rw-r--r--    1 root     root          2819 Sep  3 19:39 Los_Angeles
      -rw-r--r--    1 root     root          3519 Sep  3 19:39 New_York
      -rw-r--r--    1 root     root          2001 Sep  3 19:39 Sao_Paulo

      I removed the link and created new link to mine.

      root@Edison:~# rm /etc/localtime

      root@Edison:~# ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

      root@Edison:~# ls -l /etc/localtime
      lrwxrwxrwx    1 root     root            35 Oct 23 09:22 /etc/localtime -> /usr/share/zoneinfo/America/Chicago

      Then, I rebooted Edison, and it worked!!!

      root@Edison:~# date

      Thu Oct 23 06:33:01 CDT 2014

       

      2. Synchronizing time

      For synchronizing, I just used rdate and it worked.

      root@Edison:~# rdate wwv.nist.gov
      Thu Oct 23 12:11:10 2014

      root@Edison:~# date
      Thu Oct 23 12:11:15 CDT 2014

      The time servers that respond to rdate seem very limited. wwv.nist.gov is the only one I could find.

       

      I'm not sure if this is the right way or not, but it is working so far. Maybe, until wwv.nist.gov stops servicing ...

       

      p.s. "wwv" in wwv.nist.gov is not a typo.

        • 1. Re: Setting time zone and synchronizing time with time server on Edison
          AlexT_Intel

          That's a nice and definitely educational research, but everything is there already for automated sync and you don't need to mess up with symlinks

           

          Edison's default image has system-timesyncd enabled by default, which is using Google servers to fetch the data (the config is in /etc/systemd/timesyncd.conf):

          root@edison:~# systemctl status systemd-timesyncd

          ● systemd-timesyncd.service - Network Time Synchronization

            Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)

            Active: active (running) since Sat 2014-10-11 09:57:01 PDT; 1 weeks 5 days ago

              Docs: man:systemd-timesyncd.service(8)

          Main PID: 154 (systemd-timesyn)

            Status: "Using Time Server 216.239.36.15:123 (time3.google.com)."

            CGroup: /system.slice/systemd-timesyncd.service

                    └─154 /lib/systemd/systemd-timesyncd

           

          Dec 31 16:00:13 edison systemd-timesyncd[154]: System clock time unset or jumped backwards, restoring from recorded timestamp: Sat 2014-10-11 16:57:01 UTC

          Oct 11 09:57:01 edison systemd[1]: Started Network Time Synchronization.

          Oct 11 09:57:08 edison systemd-timesyncd[154]: Network configuration changed, trying to establish connection.

          Oct 11 09:57:08 edison systemd-timesyncd[154]: Network configuration changed, trying to establish connection.

          Oct 11 09:57:39 edison systemd-timesyncd[154]: Using NTP server 216.239.36.15:123 (time3.google.com).

          Oct 23 12:41:35 edison systemd-timesyncd[154]: interval/delta/delay/jitter/drift 32s/+1046635.705s/0.069s/0.000s/+0ppm

          Oct 23 12:42:07 edison systemd-timesyncd[154]: interval/delta/delay/jitter/drift 64s/+0.010s/0.066s/0.004s/+0ppm

          Oct 23 12:43:11 edison systemd-timesyncd[154]: interval/delta/delay/jitter/drift 128s/-0.008s/0.094s/0.012s/-32ppm

          Oct 23 12:45:19 edison systemd-timesyncd[154]: interval/delta/delay/jitter/drift 256s/+0.002s/0.095s/0.011s/-28ppm

           

          And you can manage the timezone settings (and much more) by using the dedicated utility called "timedatectl":

          root@edison:~# timedatectl status

                Local time: Thu 2014-10-23 19:45:23 UTC

            Universal time: Thu 2014-10-23 19:45:23 UTC

                  RTC time: Thu 2014-10-23 19:45:23

                Time zone: Universal (UTC, +0000)

              NTP enabled: yes

          NTP synchronized: yes

          RTC in local TZ: no

                DST active: n/a

          root@edison:~# timedatectl set-timezone America/Los_Angeles

          root@edison:~# timedatectl status

                Local time: Thu 2014-10-23 12:47:00 PDT

            Universal time: Thu 2014-10-23 19:47:00 UTC

                  RTC time: Thu 2014-10-23 19:47:00

                 Time zone: America/Los_Angeles (PDT, -0700)

               NTP enabled: yes

          NTP synchronized: yes

          RTC in local TZ: no

                DST active: yes

          Last DST change: DST began at

                            Sun 2014-03-09 01:59:59 PST

                            Sun 2014-03-09 03:00:00 PDT

          Next DST change: DST ends (the clock jumps one hour backwards) at

                            Sun 2014-11-02 01:59:59 PDT

                            Sun 2014-11-02 01:00:00 PST

           

          1 of 1 people found this helpful
          • 2. Re: Setting time zone and synchronizing time with time server on Edison
            vjou

            Thanks!!! That's exactly what I needed. I should have asked before I wasted time though I enjoyed it.

            Anyway, I hope my post have not messed up anyone's precious Edison ...

            • 3. Re: Setting time zone and synchronizing time with time server on Edison
              AlexT_Intel

              You're welcome and no worries - the steps you've described is more or less what the system does behind the scenes when you're using those utilities (except the rdate part, but it's harmless as well). That's why I wrote it's educational

              • 4. Re: Setting time zone and synchronizing time with time server on Edison
                vjou

                I had a problem about time sync that was, I guess, because of firewall. But, I think I figured out because you had given me good information already. Here is what I learned.

                 

                When I rebooted Edison, it won't show right time without doing rdate. So, I tried systemctl -l status systemd-timesyncd, but any of google time servers did not seem working.

                root@Edison:~# systemctl -l status systemd-timesyncd
                â systemd-timesyncd.service - Network Time Synchronization
                   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)
                   Active: active (running) since Thu 2014-10-23 06:31:18 CDT; 1min 18s ago
                     Docs: man:systemd-timesyncd.service(8)
                Main PID: 161 (systemd-timesyn)
                   Status: "Using Time Server 216.239.38.15:123 (time4.google.com)."
                   CGroup: /system.slice/systemd-timesyncd.service
                           ââ161 /lib/systemd/systemd-timesyncd

                Oct 23 06:31:57 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.32.15:123 (time1.google.com).
                Oct 23 06:32:07 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.32.15:123 (time1.google.com).
                Oct 23 06:32:07 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:32::f]:123 (time1.google.com).
                Oct 23 06:32:07 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.34.15:123 (time2.google.com).
                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.34.15:123 (time2.google.com).
                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:34::f]:123 (time2.google.com).
                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.36.15:123 (time3.google.com).
                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.36.15:123 (time3.google.com).
                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:36::f]:123 (time3.google.com).
                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.38.15:123 (time4.google.com).

                I found NIST Internet Time Service (Information about firewalls) and windows - How can I check a system's current NTP configuration? Then I thought it might be firewall because I'm using Edison in my office. I tried w32tm on my Windows PC.

                C:\>w32tm /query /status
                Leap Indicator: 0(no warning)
                Stratum: 3 (secondary reference - syncd by (S)NTP)
                Precision: -6 (15.625ms per tick)
                Root Delay: 0.0625000s
                Root Dispersion: 7.8404043s
                ReferenceId: 0x######## (source IP:  ###.###.###.###)
                Last Successful Sync Time: 10/23/2014 3:53:00 PM
                Source: ###.#####.###
                Poll Interval: 12 (4096s)

                Actually, "Source: ###.#####.###" above was a local time server. Thanks for your information about the configuration file, I put the address (###.#####.###) at the end of "Servers" list in /etc/systemd/timesyncd.conf.

                root@Edison:~# cat /etc/systemd/timesyncd.conf
                #  This file is part of systemd.
                #
                #  systemd is free software; you can redistribute it and/or modify it
                #  under the terms of the GNU Lesser General Public License as published by
                #  the Free Software Foundation; either version 2.1 of the License, or
                #  (at your option) any later version.
                #
                # See timesyncd.conf(5) for details

                [Time]
                Servers=time1.google.com time2.google.com time3.google.com time4.google.com ###.#####.###

                Then, I rebooted Edison. Finally, it started to work.

                root@Edison:~# systemctl status systemd-timesyncd -l
                â systemd-timesyncd.service - Network Time Synchronization
                   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)
                   Active: active (running) since Thu 2014-10-23 06:31:18 CDT; 10h ago
                     Docs: man:systemd-timesyncd.service(8)
                Main PID: 161 (systemd-timesyn)
                   Status: "Using Time Server ###.###.###.###:123 (###.#####.###)."
                   CGroup: /system.slice/systemd-timesyncd.service
                           ââ161 /lib/systemd/systemd-timesyncd

                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.34.15:123 (time2.google.com).
                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:34::f]:123 (time2.google.com).
                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.36.15:123 (time3.google.com).
                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.36.15:123 (time3.google.com).
                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:36::f]:123 (time3.google.com).
                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.38.15:123 (time4.google.com).
                Oct 23 06:32:38 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.38.15:123 (time4.google.com).
                Oct 23 06:32:38 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:38::f]:123 (time4.google.com).
                Oct 23 06:32:38 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server ###.###.###.###:123 (###.#####.###).
                Oct 23 16:48:58 PhysicsEdison2 systemd-timesyncd[161]: interval/delta/delay/jitter/drift 32s/+36980.123s/0.008s/0.000s/+0ppm

                 

                Thanks again!

                • 5. Re: Setting time zone and synchronizing time with time server on Edison
                  AlexT_Intel

                  You're welcome, glad you got it working. Nice investigation. You don't really need to restart the board after adding the server, "systemctl restart systemd-timesyncd" would do the trick (though the restart is quick anyway )

                  • 6. Re: Setting time zone and synchronizing time with time server on Edison
                    Terrence_

                    Alex, how can I get my Edison clock set and synced with the world when it is in production in the real world.

                     

                    Is there Arduino code to set the timezone and ntp server etc?

                     

                    Thanks,

                    Terrence

                    • 7. Re: Setting time zone and synchronizing time with time server on Edison
                      AlexT_Intel

                      Generally speaking, it would sync automatically upon boot, provided Google NTP servers are accessible from that network.

                      But that of course doesn't address the time zone part or the case when they aren't accessible.

                       

                      For such cases, if your primary development vehicle is the Arduino IDE, you can use system(), popen() and standard file-related C/C++ functions taking advantage of the fact that on Edison (and Galileo) the sketch is just a normal user-space process compiled as a normal Linux binary and you have access to standard libraries from the IDE along with the Arduino ones.

                       

                      Check out this document in the Galileo section: GalileoLinuxExamples.zip, even though it was initially created for Galileo, it's absolutely applicable to Edison in a sense that you can use the same functions and approaches. E.g. you can run

                      system("timedatectl set-timezone America/Los_Angeles")

                      to set the time zone.

                      • 8. Re: Setting time zone and synchronizing time with time server on Edison
                        Terrence_

                        Great info Alex.

                        Thank you.

                        Terrence

                        • 9. Re: Setting time zone and synchronizing time with time server on Edison
                          Terrence_

                          Alex, I am finally trying to get my Edison to keep track of time.

                           

                          >>Generally speaking, it would sync automatically upon boot, provided Google NTP servers are accessible from that network.

                           

                          I assume you mean if we did something to tell the board to go out and get the time.

                           

                          My board boots up and the time is 1970 etc.

                           

                          How do I get it to boot and go get the time and set it so my data going to the cloud has the correct time stamp?

                          • 10. Re: Setting time zone and synchronizing time with time server on Edison
                            mmi

                            If you have no internet access but another Linux system in your local network is active the time can be simply copied f.e. in a bash environment using

                             

                            date -s "$(/usr/bin/ssh <remoteIP> /usr/bin/date)"

                             

                            Maybe it must be modified a little bit for other shell environments.

                            • 11. Re: Setting time zone and synchronizing time with time server on Edison
                              Terrence_

                              I have internet access.

                               

                              I am talking about when my boards go into production and are out in customer's hands.  The board needs to have the correct time when it is powered up.

                              • 12. Re: Setting time zone and synchronizing time with time server on Edison
                                vjou

                                Hi Terrence_,

                                 

                                You may try systemctl -l status system-timesyncd if you have not tried yet. This command gave me some information whether Edison could reach the NTP server or not.

                                 

                                If you see something like "interval/delta/delay/jitter/drift 32s/+36980.123s/0.008s/0.000s/+0ppm" for any of NTP servers as shown below, Edison is syncing time with NTP server. If you still have problem about time on Edison, I'm sorry, but I have no clue in this case.

                                root@Edison:~# systemctl -l status systemd-timesyncd
                                â systemd-timesyncd.service - Network Time Synchronization
                                   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)
                                   Active: active (running) since Thu 2014-10-23 06:31:18 CDT; 1min 18s ago
                                     Docs: man:systemd-timesyncd.service(8)
                                Main PID: 161 (systemd-timesyn)
                                   Status: "Using Time Server 216.239.38.15:123 (time4.google.com)."
                                   CGroup: /system.slice/systemd-timesyncd.service
                                           ââ161 /lib/systemd/systemd-timesyncd

                                Oct 23 06:31:57 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.32.15:123 (time1.google.com).
                                Oct 23 06:32:07 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.32.15:123 (time1.google.com).
                                Oct 23 06:32:07 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:32::f]:123 (time1.google.com).
                                Oct 23 06:32:07 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.34.15:123 (time2.google.com).
                                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.34.15:123 (time2.google.com).
                                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:34::f]:123 (time2.google.com).
                                Oct 23 06:32:17 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server 216.239.36.15:123 (time3.google.com).
                                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Timed out waiting for reply from 216.239.36.15:123 (time3.google.com).
                                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: Using NTP server [2001:4860:4802:36::f]:123 (time3.google.com).
                                Oct 23 06:32:28 PhysicsEdison2 systemd-timesyncd[161]: interval/delta/delay/jitter/drift 32s/+36980.123s/0.008s/0.000s/+0ppm

                                 

                                If you see "Timeout ..." for all NTP servers, I think that something (maybe Firewall) is interrupting the NTP protocol getting through to the server. In my case, I could find a local time server as I posted above.

                                 

                                Though this worked for me, you may have to write startup script to find a local NTP server in your customers' environment. I do not know how to do that, so far.

                                 

                                Or, rdate command may work as I posted before, though you might have to create your own time sync script. This post may help you to create your own startup script. Also, I'm not sure how common the time server  for rdate. There is still a description about RDATE on this NIST home page and RDATE may not be so endangered as I thought.

                                • 13. Re: Setting time zone and synchronizing time with time server on Edison
                                  Terrence_

                                  vjou, thanks for that info.

                                   

                                  What tells Edison to go out and timesync in the first place?  Where can I look to see if that bit of code is in place?

                                  • 14. Re: Setting time zone and synchronizing time with time server on Edison
                                    AlexT_Intel

                                    It is supposed to do that automatically because there's a system service, systemd-timesyncd, mentioned in this thread, which autostarts when board boots. That's why I mentioned that generally you only need to have access to Google NTP servers.

                                     

                                    For example, my board at home did just that.

                                     

                                    Now if your board shows incorrect time, that may be due to various networking stuff like firewall or proxy servers - depends on your Internet connection setup.

                                    As vjou helpfully mentioned and as I've shown previously, you can use "systemctl status systemd-timesyncd" as a starting point for investigation in this case.

                                    1 2 3 Previous Next