kopia lustrzana https://github.com/micropython/micropython
extmod/ntptime: Factor out ntptime module from esp8266 port.
The ntptime module was previously only included in the ESP8266 port. This commit factors that module out into the extmod directory, makes it support different epochs, and includes it in the rp2 port.pull/8761/merge
rodzic
b560b9fe71
commit
fbe9417b90
|
@ -1,3 +1,5 @@
|
||||||
|
import utime
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import usocket as socket
|
import usocket as socket
|
||||||
except:
|
except:
|
||||||
|
@ -7,9 +9,6 @@ try:
|
||||||
except:
|
except:
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
|
|
||||||
NTP_DELTA = 3155673600
|
|
||||||
|
|
||||||
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
|
# The NTP host can be configured at runtime by doing: ntptime.host = 'myhost.org'
|
||||||
host = "pool.ntp.org"
|
host = "pool.ntp.org"
|
||||||
|
|
||||||
|
@ -26,6 +25,17 @@ def time():
|
||||||
finally:
|
finally:
|
||||||
s.close()
|
s.close()
|
||||||
val = struct.unpack("!I", msg[40:44])[0]
|
val = struct.unpack("!I", msg[40:44])[0]
|
||||||
|
|
||||||
|
EPOCH_YEAR = utime.gmtime(0)[0]
|
||||||
|
if EPOCH_YEAR == 2000:
|
||||||
|
# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
|
||||||
|
NTP_DELTA = 3155673600
|
||||||
|
elif EPOCH_YEAR == 1970:
|
||||||
|
# (date(1970, 1, 1) - date(1900, 1, 1)).days * 24*60*60
|
||||||
|
NTP_DELTA = 2208988800
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported epoch: {}".format(EPOCH_YEAR))
|
||||||
|
|
||||||
return val - NTP_DELTA
|
return val - NTP_DELTA
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +43,6 @@ def time():
|
||||||
def settime():
|
def settime():
|
||||||
t = time()
|
t = time()
|
||||||
import machine
|
import machine
|
||||||
import utime
|
|
||||||
|
|
||||||
tm = utime.gmtime(t)
|
tm = utime.gmtime(t)
|
||||||
machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))
|
machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))
|
|
@ -1,6 +1,6 @@
|
||||||
freeze("$(PORT_DIR)/modules")
|
freeze("$(PORT_DIR)/modules")
|
||||||
freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
|
freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
|
||||||
freeze("$(MPY_DIR)/ports/esp8266/modules", "ntptime.py")
|
freeze("$(MPY_DIR)/extmod", "ntptime.py")
|
||||||
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
|
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
|
||||||
freeze("$(MPY_DIR)/drivers/onewire")
|
freeze("$(MPY_DIR)/drivers/onewire")
|
||||||
include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
|
include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
freeze("$(BOARD_DIR)", "_boot.py", opt=3)
|
freeze("$(BOARD_DIR)", "_boot.py", opt=3)
|
||||||
freeze("$(PORT_DIR)/modules", ("apa102.py", "ntptime.py", "port_diag.py"))
|
|
||||||
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
|
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
|
||||||
freeze("$(MPY_DIR)/drivers/onewire")
|
freeze("$(MPY_DIR)/drivers/onewire")
|
||||||
include("$(MPY_DIR)/extmod/webrepl/manifest.py")
|
include("$(MPY_DIR)/extmod/webrepl/manifest.py")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
freeze("$(PORT_DIR)/modules")
|
freeze("$(PORT_DIR)/modules")
|
||||||
|
freeze("$(MPY_DIR)/extmod", "ntptime.py")
|
||||||
freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
|
freeze("$(MPY_DIR)/tools", ("upip.py", "upip_utarfile.py"))
|
||||||
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
|
freeze("$(MPY_DIR)/drivers/dht", "dht.py")
|
||||||
freeze("$(MPY_DIR)/drivers/onewire")
|
freeze("$(MPY_DIR)/drivers/onewire")
|
||||||
|
|
|
@ -2,6 +2,7 @@ include("../manifest.py")
|
||||||
|
|
||||||
freeze("$(MPY_DIR)/tools", "upip.py")
|
freeze("$(MPY_DIR)/tools", "upip.py")
|
||||||
freeze("$(MPY_DIR)/tools", "upip_utarfile.py")
|
freeze("$(MPY_DIR)/tools", "upip_utarfile.py")
|
||||||
|
freeze("$(MPY_DIR)/extmod", "ntptime.py")
|
||||||
|
|
||||||
if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
|
if os.path.isdir(convert_path("$(MPY_LIB_DIR)")):
|
||||||
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
|
freeze("$(MPY_LIB_DIR)/python-ecosys/urequests", "urequests.py")
|
||||||
|
|
Ładowanie…
Reference in New Issue