forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathntp.py
More file actions
28 lines (27 loc) · 639 Bytes
/
ntp.py
File metadata and controls
28 lines (27 loc) · 639 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import time
import socket
import time
from machine import RTC
TZ = 0
print("sync rtc via ntp, TZ=", TZ)
rtc = RTC()
print("synced?", rtc.synced())
rtc.ntp_sync('nl.pool.ntp.org')
print("synced?", rtc.synced())
#time.sleep_ms(750)
time.timezone(TZ * 3600)
i = 0
while True:
if rtc.synced():
print("rtc is synced after", i/1000, "s")
# if rtc.now()[0] == 1970:
# print()
break
if i % 100 == 0:
print(".", end="")
time.sleep_ms(1)
print("rtc.now", rtc.now())
print("time.gmtime", time.gmtime())
print("time.localtime", time.localtime())
print("gmt ", end=" ")
print("local", end=" ")