Thanks pythoncoder, as i know they maintain a few servers and "cn.pool.ntp.org" seem to be fastest from my location. Does it means i can modify the ntptime.py below just by changing the host to this one?
Do i need to rename this modified ntptime.py to other name before i move it to the esp board so that i can import and use it? There is already a build in ntptime module from the firmware.
import usocket as socket
import ustruct as struct
# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
NTP_DELTA = 3155673600
#host = "pool.ntp.org"
host = "cn.pool.ntp.org"
NTP_QUERY = bytearray(48)
NTP_QUERY = 0x1b
addr = socket.getaddrinfo(host, 123)[-1]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
res = s.sendto(NTP_QUERY, addr)
msg = s.recv(48)
val = struct.unpack("!I", msg[40:44])
return val - NTP_DELTA
# There's currently no timezone support in MicroPython, so
# utime.localtime() will return UTC time (as if it was .gmtime())
t = time()
tm = utime.localtime(t)
tm = tm[0:3] + (0,) + tm[3:6] + (0,)