Go Down

Topic: Local time changes when power is lost (Read 1 time) previous topic - next topic

aabm01

Hello


I'm using a Arduino Yun to send temperature and date data to a external server, every 30 seconds. The problem comes when the arduino is unplugged or lost the power. When it restarts the local time is set to 20/07/2015. To put the correct date, I have to go to Yun's 'advanced configuration panel --> System --> System' and in "System Properties --> General settings --> local Time",  press the button "Sync with browser".

After that, the date is right, but only until the power is lost again.

If it is useful, I'm using Johnny-five to program the arduino.

There are some way to ensure the correct Local Time?

There are some manual, tutorial about the 'advanced configuration panel' in Arduino Yun?

In 'advanced configuration panel --> System --> System' there are the Time Synchronization section but I don't know how to configure it

Thanks

ShapeShifter

#1
Oct 15, 2015, 12:59 pm Last Edit: Oct 15, 2015, 12:59 pm by ShapeShifter
There are some way to ensure the correct Local Time?
As you discovered, the Yun has no real time clock, so it cannot track the time when it is off. While booting, the Linux side makes som educated guesses of the current date/time by checking the modification time stamps on key files, but it doesn't really know the time until it has an Internet connection and can query an NTP server, or until you manually set the date and time.

The most reliable method to make sure the Yun has the correct local time is to add a battery backed up RTC chip to it. The easiest way to do that is probably to use an RTC shield, and write a sketch that reads the clock and sets the Linux date/time. Or, just male sure you have a valid Nternet connection and don't trust the date/time until NTP has had a chance to properly set the clock.

aabm01

Thanks for you quick answer.

The Yun is always connected to internet via wifi, because of is sending information every 30 seconds.
I'd want to use the NTP server option, but I'm not sure how it works and how to configure it in the Yun's advanced configuration panel. 

At this time the 'advanced configuration panel --> System --> System --> Time Synchronization' is set like:

  • Enable NTP client is checked.
  • Provide NTP server is checked
  • NTP server candidates are:
    • 0.openwrt.pool.ntp.org
    • 1.openwrt.pool.ntp.org
    • 2.openwrt.pool.ntp.org
    • 3.openwrt.pool.ntp.org


With this configuration when start the Yun after lose the power, the date/time the local time get to 20/07/15, so I supposed I have missed something, probably I have to reconfigure the NTP servers or add something more.

How long take the Yun to check the date/time to the NTP server?
I ask this because if the configuration above is Ok it's supposed, after a while the date/time would have to be correct, but it doesn't

I don't know if there are some place where the Yun's advanced configuration panel is explained.

Thanks.

ShapeShifter

#3
Oct 15, 2015, 04:09 pm Last Edit: Oct 15, 2015, 04:10 pm by ShapeShifter
I'd want to use the NTP server option
That won't help you. That would turn your Yun into a time server so that other computers could access it and get the time from it. This is the opposite of what you want. You want the NTP client mode, which is enabled by default.

Quote
At this time the 'advanced configuration panel --> System --> System --> Time Synchronization' is set like:
That looks correct, but uncheck the server box: it doesn't get you anything, just uses up more resources on the Yun.

Quote
How long take the Yun to check the date/time to the NTP server?
I ask this because if the configuration above is Ok it's supposed, after a while the date/time would have to be correct, but it doesn't
It should run all the time in the background, and periodically update the time, but I'm not finding any documentation on how often it does this. To make sure you have things running properly, try this command on the SSH command line:

Code: [Select]
ps | grep ntp

which on my system gives:

Code: [Select]
1649 root      1496 S    /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org
31880 root      1484 S    grep ntp


The first line shows that the ntpd process is running, and it has the the options to query the list of servers, just as you have it configured. (The second line is just the ps | grep command itself running.)

The official documentation on ntpd (scarce as it is) is here: NTP client/ NTP server [OpenWrt Wiki]

One option to speed it up is to manually request it to update the time, for example:

Code: [Select]
ntpd -q -p 0.openwrt.pool.ntp.org

This will request a time update now, and then quit once it has set the clock (you don't need to keep it running, since the automatically started process is still running in the background.) You could add this to the startup script to run each time the system boots by going to the System --> Startup tab of the advanced configuration pages, and adding it to the Local Startup file at the bottom of the page.

I tried a quick test running it manually. I changed the time, ran the command to resync the time now, and then verified the new time:

Code: [Select]
root@Yun4:/# date
Thu Oct 15 10:02:49 EDT 2015
root@Yun4:/# date 10:00
Thu Oct 15 10:00:00 EDT 2015
root@Yun4:/# date
Thu Oct 15 10:00:02 EDT 2015
root@Yun4:/# ntpd -q -p 0.openwrt.pool.ntp.org
root@Yun4:/# date
Thu Oct 15 10:00:11 EDT 2015
root@Yun4:/# date
Thu Oct 15 10:00:14 EDT 2015
root@Yun4:/# date
Thu Oct 15 10:03:13 EDT 2015
root@Yun4:/#


Looks like it took about 5 seconds actually re synchronize the clock (after running the ntpd command, I entered the date command every 2 or 3 seconds until the time changed.

aabm01

Thanks.

A very good explanation.

As you said, I uncomment the "Provide NTP server" and to get the correct data I added to the Local Startup the ntpd -q -p 0.openwrt.pool.ntp.org and it works fine.
Now when I restart my Yun it shows the correct date / Time. 

Thanks again !!!


PD: I'm going to post this subject: How to connect 3 boards to read 14 analog entrances?  If you can help I would be very grateful

Go Up