leodh
Posts: 8
Joined: Fri Apr 18, 2014 10:23 am

Need solution to set time & date by internet

Thu May 01, 2014 2:48 am

Hi All,
I have tried searching all over the net and have not been able to find a solution to the time and date settings. I have tried to follow some of the examples, they do not work or assume some knowledge which I dont have and i get lost.

I would like to record time and date for some temp readings at a set time every day, that fine I can do that. But if the power goes off for more than 1000 seconds, on reboot the RPi will not update to the correct time.

1) how can I change that 1000 seconds to something larger (eg 1 day)
2) is there a way to force a time and date update within my Python program. ( regardless of time difference.

This type of question seems to be asked a lot but there does not seem to be a universl fix.

Any help would be greatly appreciated.
Thanks Leo

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Need solution to set time & date by internet

Thu May 01, 2014 3:11 am

apt-get install ntpdate

when you want to set the date

ntpdate time.nist.gov
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
rpdom
Posts: 17170
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Need solution to set time & date by internet

Thu May 01, 2014 6:25 am

You haven't mentioned which OS you are using on your Pi.

If it is Raspbian, then it will have ntp installed which will set the time and date when it gets an internet connection.

It also has NTPD_OPTS='-g' set in /etc/default/ntp which means "ignore the 1000 seconds rule when you start up and just set the time anyway".

You shouldn't have an issue with that.

ntpdate will work, but is old and won't be supported for much longer.

leodh
Posts: 8
Joined: Fri Apr 18, 2014 10:23 am

Re: Need solution to set time & date by internet

Fri May 02, 2014 3:20 am

Sorry about that I am using Raspbain, I have tried the ntpdate even that does not work.

I have looked at 'etc/default/ntp' and I can see that it has " NTPD_OPTS='-g' " already.

Is there away to programatically ( in python ) stop the sevice ntp, ntpdate xxx.xxx.xxx.xx and then start the service agian.
Thanks again
Leo

Return to “Beginners”