【问题标题】:How to Update Date and Time of Raspberry Pi With out Internet如何在没有互联网的情况下更新树莓派的日期和时间
【发布时间】:2018-02-15 09:36:23
【问题描述】:

我已将 Raspberry Pi 连接到 LAN,但没有可用的互联网。有什么方法可以通过在 LAN 中使用 PC(Windows 7)来更新树莓派日期时间?我想在 Raspberry Pi 启动时获取计算机的日期和时间。

【问题讨论】:

标签: raspberry-pi


【解决方案1】:

请记住,Raspberry Pi 没有实时时钟。因此,即使您已连接到互联网,也必须在每次开机或重启时设置时间。

这就是它的工作原理:

  1. 在树莓派命令行中输入sudo raspi-config
  2. 国际化选项
  3. 更改时区
  4. 选择地理区域
  5. 选择城市或地区
  6. 重启你的 pi

接下来你可以使用这个命令设置时间

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

更多关于数据和时间的信息

man date

当 Pi 连接电脑时,需要手动设置数据和时间

【讨论】:

  • 这不能回答问题。
【解决方案2】:

感谢您的回复。
我所做的是,
1. 我在 Windows 7 电脑上安装了meinberg ntp software 应用程序。 (softros ntp 服务器也可以。)
2. 更改树莓派 ntp.conf 文件(用于自动更新日期和时间)

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。如果您想确保在启动时更新日期和时间,请在 rpi 中运行此 python 脚本,

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

我在树莓派论坛找到more info

【讨论】:

    【解决方案3】:

    您需要将您的 Win7 PC 配置为时间服务器,然后配置 RasPi 以连接到它以使用 NTP 服务。

    将 Win7 配置为authoritative time server。 配置 RasPi time server lookup

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 2022-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多