adafruit-circuitpython-ntp 3.1.0__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/PKG-INFO +2 -2
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/README.rst +1 -1
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/adafruit_circuitpython_ntp.egg-info/PKG-INFO +2 -2
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/adafruit_ntp.py +12 -7
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/examples/ntp_connection_manager.py +2 -2
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/examples/ntp_cpython.py +1 -1
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/examples/ntp_set_rtc.py +1 -1
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/examples/ntp_simpletest.py +1 -1
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/pyproject.toml +1 -1
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.github/workflows/build.yml +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.github/workflows/failure-help-text.yml +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.github/workflows/release_gh.yml +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.github/workflows/release_pypi.yml +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.gitignore +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.pre-commit-config.yaml +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.pylintrc +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.readthedocs.yaml +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/CODE_OF_CONDUCT.md +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/LICENSE +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/LICENSES/CC-BY-4.0.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/LICENSES/MIT.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/LICENSES/Unlicense.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/README.rst.license +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/adafruit_circuitpython_ntp.egg-info/SOURCES.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/adafruit_circuitpython_ntp.egg-info/dependency_links.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/adafruit_circuitpython_ntp.egg-info/requires.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/adafruit_circuitpython_ntp.egg-info/top_level.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/_static/favicon.ico +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/_static/favicon.ico.license +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/api.rst +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/api.rst.license +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/conf.py +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/examples.rst +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/examples.rst.license +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/index.rst +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/index.rst.license +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/requirements.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/optional_requirements.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/requirements.txt +0 -0
- {adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: adafruit-circuitpython-ntp
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: Network Time Protocol (NTP) helper for Python
|
|
5
5
|
Author-email: Adafruit Industries <circuitpython@adafruit.com>
|
|
6
6
|
License: MIT
|
|
@@ -89,7 +89,7 @@ Usage Example
|
|
|
89
89
|
wifi.radio.connect(wifi_ssid, wifi_password)
|
|
90
90
|
|
|
91
91
|
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
|
92
|
-
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
92
|
+
ntp = adafruit_ntp.NTP(pool, tz_offset=0, cache_seconds=3600)
|
|
93
93
|
|
|
94
94
|
while True:
|
|
95
95
|
print(ntp.datetime)
|
|
@@ -70,7 +70,7 @@ Usage Example
|
|
|
70
70
|
wifi.radio.connect(wifi_ssid, wifi_password)
|
|
71
71
|
|
|
72
72
|
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
|
73
|
-
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
73
|
+
ntp = adafruit_ntp.NTP(pool, tz_offset=0, cache_seconds=3600)
|
|
74
74
|
|
|
75
75
|
while True:
|
|
76
76
|
print(ntp.datetime)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: adafruit-circuitpython-ntp
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: Network Time Protocol (NTP) helper for Python
|
|
5
5
|
Author-email: Adafruit Industries <circuitpython@adafruit.com>
|
|
6
6
|
License: MIT
|
|
@@ -89,7 +89,7 @@ Usage Example
|
|
|
89
89
|
wifi.radio.connect(wifi_ssid, wifi_password)
|
|
90
90
|
|
|
91
91
|
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
|
92
|
-
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
92
|
+
ntp = adafruit_ntp.NTP(pool, tz_offset=0, cache_seconds=3600)
|
|
93
93
|
|
|
94
94
|
while True:
|
|
95
95
|
print(ntp.datetime)
|
|
@@ -25,7 +25,7 @@ import time
|
|
|
25
25
|
from micropython import const
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
__version__ = "3.
|
|
28
|
+
__version__ = "3.2.0"
|
|
29
29
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NTP.git"
|
|
30
30
|
|
|
31
31
|
NTP_TO_UNIX_EPOCH = 2208988800 # 1970-01-01 00:00:00
|
|
@@ -46,6 +46,7 @@ class NTP:
|
|
|
46
46
|
port: int = 123,
|
|
47
47
|
tz_offset: float = 0,
|
|
48
48
|
socket_timeout: int = 10,
|
|
49
|
+
cache_seconds: int = 0,
|
|
49
50
|
) -> None:
|
|
50
51
|
"""
|
|
51
52
|
:param object socketpool: A socket provider such as CPython's `socket` module.
|
|
@@ -55,6 +56,8 @@ class NTP:
|
|
|
55
56
|
CircuitPython. CPython will determine timezone automatically and adjust (so don't use
|
|
56
57
|
this.) For example, Pacific daylight savings time is -7.
|
|
57
58
|
:param int socket_timeout: UDP socket timeout, in seconds.
|
|
59
|
+
:param int cache_seconds: how many seconds to use a cached result from NTP server
|
|
60
|
+
(default 0, which respects NTP server's minimum).
|
|
58
61
|
"""
|
|
59
62
|
self._pool = socketpool
|
|
60
63
|
self._server = server
|
|
@@ -63,6 +66,7 @@ class NTP:
|
|
|
63
66
|
self._packet = bytearray(PACKET_SIZE)
|
|
64
67
|
self._tz_offset = int(tz_offset * 60 * 60)
|
|
65
68
|
self._socket_timeout = socket_timeout
|
|
69
|
+
self._cache_seconds = cache_seconds
|
|
66
70
|
|
|
67
71
|
# This is our estimated start time for the monotonic clock. We adjust it based on the ntp
|
|
68
72
|
# responses.
|
|
@@ -74,7 +78,8 @@ class NTP:
|
|
|
74
78
|
def datetime(self) -> time.struct_time:
|
|
75
79
|
"""Current time from NTP server. Accessing this property causes the NTP time request,
|
|
76
80
|
unless there has already been a recent request. Raises OSError exception if no response
|
|
77
|
-
is received within socket_timeout seconds
|
|
81
|
+
is received within socket_timeout seconds, ArithmeticError for substantially incorrect
|
|
82
|
+
NTP results."""
|
|
78
83
|
if time.monotonic_ns() > self.next_sync:
|
|
79
84
|
if self._socket_address is None:
|
|
80
85
|
self._socket_address = self._pool.getaddrinfo(self._server, self._port)[
|
|
@@ -85,18 +90,18 @@ class NTP:
|
|
|
85
90
|
for i in range(1, PACKET_SIZE):
|
|
86
91
|
self._packet[i] = 0
|
|
87
92
|
with self._pool.socket(self._pool.AF_INET, self._pool.SOCK_DGRAM) as sock:
|
|
88
|
-
# Since the ESP32SPI doesn't support sendto, we are using
|
|
89
|
-
# connect + send to standardize code
|
|
90
93
|
sock.settimeout(self._socket_timeout)
|
|
91
|
-
sock.
|
|
92
|
-
sock.send(self._packet)
|
|
94
|
+
sock.sendto(self._packet, self._socket_address)
|
|
93
95
|
sock.recv_into(self._packet)
|
|
94
96
|
# Get the time in the context to minimize the difference between it and receiving
|
|
95
97
|
# the packet.
|
|
96
98
|
destination = time.monotonic_ns()
|
|
97
99
|
poll = struct.unpack_from("!B", self._packet, offset=2)[0]
|
|
98
|
-
|
|
100
|
+
|
|
101
|
+
cache_offset = max(2**poll, self._cache_seconds)
|
|
102
|
+
self.next_sync = destination + cache_offset * 1_000_000_000
|
|
99
103
|
seconds = struct.unpack_from("!I", self._packet, offset=PACKET_SIZE - 8)[0]
|
|
104
|
+
|
|
100
105
|
self._monotonic_start = (
|
|
101
106
|
seconds
|
|
102
107
|
+ self._tz_offset
|
|
@@ -33,7 +33,7 @@ except ImportError:
|
|
|
33
33
|
# get the socket pool from connection manager
|
|
34
34
|
socket = adafruit_connection_manager.get_radio_socketpool(radio)
|
|
35
35
|
|
|
36
|
-
# adjust tz_offset for locale
|
|
37
|
-
ntp = adafruit_ntp.NTP(socket, tz_offset=-5)
|
|
36
|
+
# adjust tz_offset for locale, only ping NTP server every hour
|
|
37
|
+
ntp = adafruit_ntp.NTP(socket, tz_offset=-5, cache_seconds=3600)
|
|
38
38
|
|
|
39
39
|
print(ntp.datetime)
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/examples/ntp_set_rtc.py
RENAMED
|
@@ -21,7 +21,7 @@ except ImportError:
|
|
|
21
21
|
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
|
22
22
|
|
|
23
23
|
pool = socketpool.SocketPool(wifi.radio)
|
|
24
|
-
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
24
|
+
ntp = adafruit_ntp.NTP(pool, tz_offset=0, cache_seconds=3600)
|
|
25
25
|
|
|
26
26
|
# NOTE: This changes the system time so make sure you aren't assuming that time
|
|
27
27
|
# doesn't jump.
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/examples/ntp_simpletest.py
RENAMED
|
@@ -20,7 +20,7 @@ except ImportError:
|
|
|
20
20
|
wifi.radio.connect(secrets["ssid"], secrets["password"])
|
|
21
21
|
|
|
22
22
|
pool = socketpool.SocketPool(wifi.radio)
|
|
23
|
-
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
23
|
+
ntp = adafruit_ntp.NTP(pool, tz_offset=0, cache_seconds=3600)
|
|
24
24
|
|
|
25
25
|
while True:
|
|
26
26
|
print(ntp.datetime)
|
|
@@ -12,7 +12,7 @@ requires = [
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "adafruit-circuitpython-ntp"
|
|
14
14
|
description = "Network Time Protocol (NTP) helper for Python"
|
|
15
|
-
version = "3.
|
|
15
|
+
version = "3.2.0"
|
|
16
16
|
readme = "README.rst"
|
|
17
17
|
authors = [
|
|
18
18
|
{name = "Adafruit Industries", email = "circuitpython@adafruit.com"}
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.github/workflows/build.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/.pre-commit-config.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/LICENSES/CC-BY-4.0.txt
RENAMED
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/LICENSES/Unlicense.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/_static/favicon.ico
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/examples.rst.license
RENAMED
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/docs/index.rst.license
RENAMED
|
File without changes
|
|
File without changes
|
{adafruit_circuitpython_ntp-3.1.0 → adafruit_circuitpython_ntp-3.2.0}/optional_requirements.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|