def set_NTP_time():
import time
from pyb import RTC
print("Setting time from NTP")
t = get_NTP_time()
if t is None:
print("Could not set time from NTP")
return False
tz = 0
with database.Database() as db:
tz = db.get("timezone", 0)
tz_minutes = int(abs(tz) % 100) * (1 if tz >= 0 else -1)
tz_hours = int(tz / 100)
t += (tz_hours * 3600) + (tz_minutes * 60)
tm = time.localtime(t)
tm = tm[0:3] + (0,) + tm[3:6] + (0,)
rtc = RTC()
rtc.init()
rtc.datetime(tm)
return True
评论列表
文章目录