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

后端 未结 3 981
感情败类
感情败类 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: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.

提交回复
热议问题