Code: Select all
MicroPython v1.12 on 2019-12-20; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> import ntptime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'ntptime'
>>>
Code: Select all
MicroPython v1.12 on 2019-12-20; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> import ntptime
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'ntptime'
>>>
Code: Select all
content = http_get('http://micropython.org/ks/test.html')
# t1 = utime.ticks_ms()
start_idx = content.index("Date: ")
end_idx = content.index("\r\n", start_idx+1)
date = content[start_idx+len("Date: "):end_idx]
print("HTTP GM time: {}".format(date))
# Tue, 06 Apr 2021 06:26:18 GMT
words = date.split()
# print(words)
month = months[words[2]]
weekday = weekdays[words[0][:3]]
hms = words[4].split(':')
datetime = [
int(words[3]),
month,
int(words[1]),
int(hms[0]),
int(hms[1]),
int(hms[2]),
weekday + 1,
0,
]
print("HTTP GM time: {}".format(datetime))
jan_1_2000_secs = utime.mktime(datetime)
SECS_PER_HOUR = 3600
TZ = -7
jan_1_2000_secs += SECS_PER_HOUR * TZ
# calc_ms = utime.ticks_ms() - t1
# calc_s = round(calc_ms / 1000)
# jan_1_2000_secs += calc_s # Add in any time lost while performing these calculations (removed since the cost turned out to be negligible)
datetime = utime.localtime(jan_1_2000_secs)
print("Local time: {}".format(datetime))
# machine.RTC().datetime(datetime)
machine.RTC().datetime((datetime[0], datetime[1], datetime[2], datetime[6] + 1, datetime[3], datetime[4], datetime[5], 0))
# print("Calc time: {} {}".format(calc_ms, calc_s))
print("Local time: {}".format(utime.localtime()))
print("GM time: {}".format(utime.gmtime()))