udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

How to Update Date and Time With out Internet

Sun Aug 17, 2014 8:58 am

I have connect my RPi to LAN but there is no internet available so is there any method to update RPi date time by using a PC in LAN. I want to get computer date and time to my RPi when it booting.
Thanks.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to Update Date and Time With out Internet

Sun Aug 17, 2014 9:37 am

Lots of ways to do this, but the key questions are:

1) What OS is your PC running?

2) How much programming are you willing/able to do?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Sun Aug 17, 2014 9:44 am

I'm using Windows 7 on my PC and I'm not an expert on programming but I think I can handle.

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Wed Aug 20, 2014 1:17 pm

Is it possible to start a NTP server in my PC and then add its IP address in raspberry pi ntp pool.
Thanks.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to Update Date and Time With out Internet

Wed Aug 20, 2014 1:19 pm

udara wrote:Is it possible to start a NTP server in my PC and then add its IP address in raspberry pi ntp pool.
Thanks.
That's a great idea. You should try it!

User avatar
r3d4
Posts: 982
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: How to Update Date and Time With out Internet

Wed Aug 20, 2014 1:32 pm

pi + camera + sundial !
Then just create some sundial tracking software/app's ,.. done .

That or some kind of http://en.wikipedia.org/wiki/Radio_clock ?
Now i iread fully your question you want to update 'With out Internet' but with LAN ! .
Guess the pi-sundial was never met to be ;P
Real life is, to most, a long second-best, a perpetual compromise between the ideal and the possible.
-
Meanwhile, the sysadmin who accidentally nuked the data reckons "its best not run anything more with sudo today"
-
what about spike milligan?

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to Update Date and Time With out Internet

Wed Aug 20, 2014 2:04 pm

The key thing in this thread is that the work has to be done on the Windows side.

Once you have some kind of server running on the Windows, the Pi side is trivial.

Unfortunately, no one here is likely to want to help you with Windows problems.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Wed Aug 20, 2014 2:29 pm

Thanks for the ideas.
I found out few options update raspberry pi date time without internet.
1. Starting NTP server in a PC. http://social.technet.microsoft.com/For ... inserverPN
2. Using a RTC module. http://afterthoughtsoftware.com/products/rasclock
Mainly I'm try to start a NTP server in PC.
Thanks.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to Update Date and Time With out Internet

Wed Aug 20, 2014 8:16 pm

udara wrote: Mainly I'm try to start a NTP server in PC.
Thanks.
If you can get this working, let us all know. It could be useful.

If not, I have a few "roll my own" solutions that I've created and used over the years.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

hippy
Posts: 7739
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How to Update Date and Time With out Internet

Thu Aug 21, 2014 12:26 am

One option may be to use a TCP 'daytime' server and client rather than NTP. If not already present ( check Simple TCP/IP Services under Windows ), client or server should be fairly trivial to code, the Windows server software probably easier than the client.

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Sat Aug 23, 2014 12:27 pm

I enabled NTP server from windows registry and enabled time service from administrative tools - services and then I open TCP and UDP port 123 then I add my pc ip address to ntp.conf but it didn't work.
I would really appreciate if someone can give me some points or a different method to do this.
Thanks.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to Update Date and Time With out Internet

Sat Aug 23, 2014 1:40 pm

udara wrote:I enabled NTP server from windows registry and enabled time service from administrative tools - services and then I open TCP and UDP port 123 then I add my pc ip address to ntp.conf but it didn't work.
I would really appreciate if someone can give me some points or a different method to do this.
Thanks.
The problem is that all solutions are basically equivalent - they all require mucking about in Windows, and defeating all the lame-o "security" mis-features of Windows. I have no doubt that if you mucked with it long enough, you could get NTP working under Windows. But you would feel dirty for having done so.

My preferred solution is to run an rdate server (Cygwin-compilable source is attached - that is, if I can get the attachment feature working on this brain-dead board software…) on the Windows box and use rdate (available via "apt-get install rdate") on the Pi side.
Attachments
rdate_server.zip
An 'rdate' server on port 3737.
(699 Bytes) Downloaded 114 times
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: How to Update Date and Time With out Internet

Sun Aug 24, 2014 12:08 am

udara wrote:I enabled NTP server from windows registry and ...
problem == opportunity to learn something new

Run this on the machine that knows what time it is:

Code: Select all

import socket
import time
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
while 1:
    s.sendto(str(time.time()), ('255.255.255.255',55555))
    time.sleep(10-(time.time() % 10))
It broadcasts the current time every 10 seconds over UDP.
Then you run this on the system that wants to learn the time:

Code: Select all

import socket
import time
import os
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('',55555))
while 1:
    l = s.recv(100)
    t = float(l)
    d = t - time.time()
    if (abs(d) > 1):
        os.system('echo sudo date %s' % time.strftime('%m%d%H%M%Y.%S', time.localtime(t)))
    else:
        print(l,t,d)
It will print out the date command necessary to set adjust the time.
Try it, and if it seems to be doing the right thing take out the echo and it will set the time automagically.

No, this is not the easiest way to do it, but it is going to teach you a few things about python, UDP, startup scripts, ...

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to Update Date and Time With out Internet

Sun Aug 24, 2014 12:24 am

Here you are:
http://www.satsignal.eu/ntp/setup.html
udara wrote:I enabled NTP server from windows registry and enabled time service from administrative tools - services and then I open TCP and UDP port 123 then I add my pc ip address to ntp.conf but it didn't work.
I would really appreciate if someone can give me some points or a different method to do this.
Thanks.

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Sun Aug 24, 2014 10:19 am

Thanks for the replies,
Now I think NTP service is running on my pc,
http://windowsforum.com/threads/windows ... ost-159346
http://javadotnet.in/2013/01/create-you ... windows-7/
I checked with following python code

Code: Select all

import ntplib
from time import ctime

c = ntplib.NTPClient()
response = c.request('192.168.1.100', version=3)
#response = c.request('europe.pool.ntp.org', version=3)

print response.offset
print response.version
print ctime(response.tx_time)
print ntplib.leap_to_text(response.leap)
print response.root_delay
print ntplib.ref_id_to_text(response.ref_id)
when I run this code in RPi it gives following out put in screen shot. Then I add ip address to ntp.conf

Code: Select all

server 0.192.168.1.100
but RPi is not update its date time automatically. Is this the correct way to change ntp.conf ?
I think it is possible to set date time by using

Code: Select all

date -s <date string> 
If RPi not update automatically I'm thinking get date and time using this code and then update RPi date and time when booting, Is this possible ?
Thanks.
Attachments
time.png
time.png (52.15 KiB) Viewed 7364 times

morgad
Posts: 21
Joined: Sun Jan 29, 2012 10:24 pm
Contact: Website

Re: How to Update Date and Time With out Internet

Sun Aug 24, 2014 1:01 pm

try

Code: Select all

server 192.168.1.100 iburst
(there was an extra 0. at the front)
iburst added for faster start-up

best regards
Dave

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 5:06 am

Thanks.
I changed it but it didn't work.
When RPi update its date time? at start up only or any time when internet available?
Thanks.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 5:27 am

If so then
udara wrote:Now I think NTP service is running on my pc,
It may be running, but it's probably not serving the time, or it's being firewalled or something silly.

try ntpq -np on the pi and post the result. It should look something like:

Code: Select all

$ ntpq -np
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+27.54.95.12     233.171.100.138  3 u   92 1024  377   85.189   -7.976   7.993
try running

Code: Select all

tcpdump -npi any udp port 123
on the Pi.
You should eventually see somthing like

Code: Select all

$ sudo tcpdump -npi any udp port 123
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
14:53:33.794425 IP 192.168.1.93.123 > 27.54.95.12.123: NTPv4, Client, length 48
14:53:33.889467 IP 27.54.95.12.123 > 192.168.1.93.123: NTPv4, Server, length 48
(with different IP addresses, but you get the idea...)

My guess is that the last line will be missing, i.e. the Pi will ask for the time but Windows won't respond.

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 6:24 am

Thanks for the reply,
I ran those commands (in screen shot) and I think there is version mismatch if I'm right how can i resolve it or is it a different issue?
Thanks.
Attachments
tcpdump.gif
tcpdump.gif (42.67 KiB) Viewed 7275 times

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 6:43 am

Your time server at 192.168.1.100 is not answering any UDP time queries on port UDP 123.

So take a look at that machine; is it running an NTP server? is that server set-up to allow peering or remote clients? does that server have a firewall that blocks inbound requests on port UDP 123?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 6:57 am

udara wrote:Thanks for the reply,
I ran those commands (in screen shot) and I think there is version mismatch if I'm right how can i resolve it or is it a different issue?
Thanks.
(text cut-and-paste will do fine, no need for a graphical screnshot).

OK... the "st" is stratum, lower is better.
Stratum 0 is a GPS-loocked clock, or some other type of very accurate referance.
stratum 16 is "I have no clue what time it is".
The ".init." in the ntpq command means "don't bother me yet, I haven't figured out what time it is"
So... the server isn't ready to provide time because it knows that it does not have a reliable referance.
There's a way to make it pretend. On Linux you would add something like this:

Code: Select all

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10
in /etc/ntp/conf
Not sure how to do it on Windows (might be the same, don't have a windows box to test with).

udara
Posts: 50
Joined: Fri Jul 11, 2014 3:27 pm

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 11:25 am

Thanks for replies,
I tried out different ways setup a NTP server
1. http://nts.softros.com/ this is a great server and raspberry pi automatically update date and time unfortunately it need license.
2.As "ame" suggest http://www.satsignal.eu/ntp/setup.html this is free and work nicely but some times RPi take about 30s to update its date and time.
So I'm thinking to use 2 option but still try to configure NTP service in windows 7.
Thanks.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 11:54 am

Were you able to compile and use the rdate_server program?

That's clearly the easiest way to do this - instead of all this mucking with the guts of the ntp* programs.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 12:00 pm

Joe Schmoe wrote:Were you able to compile and use the rdate_server program?

That's clearly the easiest way to do this - instead of all this mucking with the guts of the ntp* programs.
The easiest way to do it is to get the well-known, standards-based programs working.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: How to Update Date and Time With out Internet

Mon Aug 25, 2014 12:53 pm

ame wrote:
Joe Schmoe wrote:Were you able to compile and use the rdate_server program?

That's clearly the easiest way to do this - instead of all this mucking with the guts of the ntp* programs.
The easiest way to do it is to get the well-known, standards-based programs working.
Start with the PC's OS :-)

http://www.debian.org/

Return to “Beginners”