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

后端 未结 3 974
感情败类
感情败类 2021-02-07 01:15

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 co

相关标签:
3条回答
  • 2021-02-07 01:43

    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

    0 讨论(0)
  • 2021-02-07 01:45

    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.

    0 讨论(0)
  • 2021-02-07 01:54

    You will need to configure your Win7 PC as a Time Server, and then configure the RasPi to connect to it for NTP services.

    Configure Win7 as authoritative time server. Configure RasPi time server lookup.

    0 讨论(0)
提交回复
热议问题