时间终于同步,存储成功

This commit is contained in:
2026-08-28 21:10:51 +08:00
parent ad154b2f7e
commit 1781833767
13 changed files with 606 additions and 78 deletions
+6 -2
View File
@@ -24,6 +24,7 @@ import socket
import struct
import sys
import time
import calendar
DEFAULT_MCU_IP = "192.168.1.100"
DEFAULT_PORT = 8888
@@ -44,8 +45,11 @@ def main():
while True:
try:
# 本地 wall-clock 的 epoch(与电脑显示一致;板子按本地时间分解)
local_epoch = int(time.mktime(time.localtime()))
# 本地 wall-clock 当作 UTC 算出的 epoch(与电脑显示一致)。
# 注意:板子 RTC 存本地时间且 unix_to_sd2506 无时区处理,
# 故必须发"本地墙钟当 UTC"的伪 epoch(calendar.timegm),
# 不能用 time.mktime(返回真正 UTC epoch,会导致板子慢 8 小时)。
local_epoch = int(calendar.timegm(time.localtime()))
pkt = b"TIME" + struct.pack(">I", local_epoch)
with socket.create_connection((mcu_ip, port), timeout=5) as sock: