Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Update Date and Time of Raspberry Pi With out Internet

Tags:

I have connect my Raspberry Pi to LAN but there is no internet available. Is there any method to update raspberry pi date time by using a PC (windows 7) in LAN? I want to get computer date and time to my Raspberry Pi when it is booting.

like image 770
Udara Avatar asked Aug 19 '14 01:08

Udara


People also ask

How do I manually change the time on my Raspberry Pi?

In the main menu, go to Preferences > Raspberry Pi Configuration. In the “Localisation” tab, you can change the current time zone: Choose the one corresponding to your location, and click on “Ok” twice to save the changes. A few seconds later, the time should be updated in the top-right corner.

How do I update my Raspberry Pi remotely?

To update the packages on your Raspberry Pi, open a terminal window or connect to your Pi remotely using an SSH client. You'll first need to update the list of packages from the software repository package lists. To do this type sudo apt update, then hit enter to run it.

How do I force a Raspberry Pi to update?

You can do this by opening a new terminal window and entering the command sudo rpi-eeprom-update . If it flags that an update is available, as we mentioned earlier, one option is to run sudo apt update followed by sudo apt full-upgrade to fully update your Pi's software, firmware included.


2 Answers

Remember that Raspberry Pi does not have real time clock. So even you are connected to internet have to set the time every time you power on or restart.

This is how it works:

  1. Type sudo raspi-config in the Raspberry Pi command line
  2. Internationalization options
  3. Change Time Zone
  4. Select geographical area
  5. Select city or region
  6. Reboot your pi

Next thing you can set time using this command

sudo date -s "Mon Aug  12 20:14:11 UTC 2014" 

More about data and time

man date 

When Pi is connected to computer should have to manually set data and time

like image 125
GPrathap Avatar answered Sep 27 '22 21:09

GPrathap


Thanks for the replies.
What I did was,
1. I install meinberg ntp software application on windows 7 pc. (softros ntp server is also possible.)
2. change raspberry pi ntp.conf file (for auto update date and time)

server xxx.xxx.xxx.xxx iburst server 1.debian.pool.ntp.org iburst server 2.debian.pool.ntp.org iburst server 3.debian.pool.ntp.org iburst 

3. If you want to make sure that date and time update at startup run this python script in rpi,

import os  try:     client = ntplib.NTPClient()     response = client.request('xxx.xxx.xxx.xxx', version=4)     print "===================================="     print "Offset : "+str(response.offset)     print "Version : "+str(response.version)     print "Date Time : "+str(ctime(response.tx_time))     print "Leap : "+str(ntplib.leap_to_text(response.leap))     print "Root Delay : "+str(response.root_delay)     print "Ref Id : "+str(ntplib.ref_id_to_text(response.ref_id))     os.system("sudo date -s '"+str(ctime(response.tx_time))+"'")     print "====================================" except:     os.system("sudo date")     print "NTP Server Down Date Time NOT Set At The Startup"     pass 

I found more info in raspberry pi forum.

like image 25
Udara Avatar answered Sep 27 '22 21:09

Udara