adafruit-circuitpython-ntp 3.0.12__tar.gz → 3.1.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.0.12 → adafruit_circuitpython_ntp-3.1.0}/PKG-INFO +7 -11
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/README.rst +6 -10
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/adafruit_circuitpython_ntp.egg-info/PKG-INFO +7 -11
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/adafruit_circuitpython_ntp.egg-info/SOURCES.txt +1 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/adafruit_ntp.py +19 -8
- adafruit_circuitpython_ntp-3.1.0/examples/ntp_connection_manager.py +39 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/pyproject.toml +1 -1
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.github/workflows/build.yml +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.github/workflows/failure-help-text.yml +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.github/workflows/release_gh.yml +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.github/workflows/release_pypi.yml +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.gitignore +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.pre-commit-config.yaml +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.pylintrc +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/.readthedocs.yaml +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/CODE_OF_CONDUCT.md +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/LICENSE +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/LICENSES/CC-BY-4.0.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/LICENSES/MIT.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/LICENSES/Unlicense.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/README.rst.license +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/adafruit_circuitpython_ntp.egg-info/dependency_links.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/adafruit_circuitpython_ntp.egg-info/requires.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/adafruit_circuitpython_ntp.egg-info/top_level.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/_static/favicon.ico +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/_static/favicon.ico.license +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/api.rst +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/api.rst.license +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/conf.py +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/examples.rst +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/examples.rst.license +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/index.rst +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/index.rst.license +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/requirements.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/examples/ntp_cpython.py +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/examples/ntp_set_rtc.py +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/examples/ntp_simpletest.py +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/optional_requirements.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/requirements.txt +0 -0
- {adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: adafruit-circuitpython-ntp
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: Network Time Protocol (NTP) helper for Python
|
|
5
5
|
Author-email: Adafruit Industries <circuitpython@adafruit.com>
|
|
6
6
|
License: MIT
|
|
@@ -78,21 +78,17 @@ Usage Example
|
|
|
78
78
|
|
|
79
79
|
.. code-block:: python
|
|
80
80
|
|
|
81
|
+
import adafruit_connection_manager
|
|
81
82
|
import adafruit_ntp
|
|
82
|
-
import
|
|
83
|
+
import os
|
|
83
84
|
import time
|
|
84
85
|
import wifi
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
except ImportError:
|
|
90
|
-
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
91
|
-
raise
|
|
87
|
+
wifi_ssid = os.getenv("CIRCUITPY_WIFI_SSID")
|
|
88
|
+
wifi_password = os.getenv("CIRCUITPY_WIFI_PASSWORD")
|
|
89
|
+
wifi.radio.connect(wifi_ssid, wifi_password)
|
|
92
90
|
|
|
93
|
-
wifi.radio
|
|
94
|
-
|
|
95
|
-
pool = socketpool.SocketPool(wifi.radio)
|
|
91
|
+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
|
96
92
|
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
97
93
|
|
|
98
94
|
while True:
|
|
@@ -59,21 +59,17 @@ Usage Example
|
|
|
59
59
|
|
|
60
60
|
.. code-block:: python
|
|
61
61
|
|
|
62
|
+
import adafruit_connection_manager
|
|
62
63
|
import adafruit_ntp
|
|
63
|
-
import
|
|
64
|
+
import os
|
|
64
65
|
import time
|
|
65
66
|
import wifi
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
except ImportError:
|
|
71
|
-
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
72
|
-
raise
|
|
68
|
+
wifi_ssid = os.getenv("CIRCUITPY_WIFI_SSID")
|
|
69
|
+
wifi_password = os.getenv("CIRCUITPY_WIFI_PASSWORD")
|
|
70
|
+
wifi.radio.connect(wifi_ssid, wifi_password)
|
|
73
71
|
|
|
74
|
-
wifi.radio
|
|
75
|
-
|
|
76
|
-
pool = socketpool.SocketPool(wifi.radio)
|
|
72
|
+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
|
77
73
|
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
78
74
|
|
|
79
75
|
while True:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: adafruit-circuitpython-ntp
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: Network Time Protocol (NTP) helper for Python
|
|
5
5
|
Author-email: Adafruit Industries <circuitpython@adafruit.com>
|
|
6
6
|
License: MIT
|
|
@@ -78,21 +78,17 @@ Usage Example
|
|
|
78
78
|
|
|
79
79
|
.. code-block:: python
|
|
80
80
|
|
|
81
|
+
import adafruit_connection_manager
|
|
81
82
|
import adafruit_ntp
|
|
82
|
-
import
|
|
83
|
+
import os
|
|
83
84
|
import time
|
|
84
85
|
import wifi
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
except ImportError:
|
|
90
|
-
print("WiFi secrets are kept in secrets.py, please add them there!")
|
|
91
|
-
raise
|
|
87
|
+
wifi_ssid = os.getenv("CIRCUITPY_WIFI_SSID")
|
|
88
|
+
wifi_password = os.getenv("CIRCUITPY_WIFI_PASSWORD")
|
|
89
|
+
wifi.radio.connect(wifi_ssid, wifi_password)
|
|
92
90
|
|
|
93
|
-
wifi.radio
|
|
94
|
-
|
|
95
|
-
pool = socketpool.SocketPool(wifi.radio)
|
|
91
|
+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
|
96
92
|
ntp = adafruit_ntp.NTP(pool, tz_offset=0)
|
|
97
93
|
|
|
98
94
|
while True:
|
|
@@ -22,10 +22,14 @@ Implementation Notes
|
|
|
22
22
|
import struct
|
|
23
23
|
import time
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
from micropython import const
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
__version__ = "3.1.0"
|
|
26
29
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NTP.git"
|
|
27
30
|
|
|
28
31
|
NTP_TO_UNIX_EPOCH = 2208988800 # 1970-01-01 00:00:00
|
|
32
|
+
PACKET_SIZE = const(48)
|
|
29
33
|
|
|
30
34
|
|
|
31
35
|
class NTP:
|
|
@@ -55,7 +59,8 @@ class NTP:
|
|
|
55
59
|
self._pool = socketpool
|
|
56
60
|
self._server = server
|
|
57
61
|
self._port = port
|
|
58
|
-
self.
|
|
62
|
+
self._socket_address = None
|
|
63
|
+
self._packet = bytearray(PACKET_SIZE)
|
|
59
64
|
self._tz_offset = int(tz_offset * 60 * 60)
|
|
60
65
|
self._socket_timeout = socket_timeout
|
|
61
66
|
|
|
@@ -71,21 +76,27 @@ class NTP:
|
|
|
71
76
|
unless there has already been a recent request. Raises OSError exception if no response
|
|
72
77
|
is received within socket_timeout seconds"""
|
|
73
78
|
if time.monotonic_ns() > self.next_sync:
|
|
79
|
+
if self._socket_address is None:
|
|
80
|
+
self._socket_address = self._pool.getaddrinfo(self._server, self._port)[
|
|
81
|
+
0
|
|
82
|
+
][4]
|
|
83
|
+
|
|
74
84
|
self._packet[0] = 0b00100011 # Not leap second, NTP version 4, Client mode
|
|
75
|
-
for i in range(1,
|
|
85
|
+
for i in range(1, PACKET_SIZE):
|
|
76
86
|
self._packet[i] = 0
|
|
77
87
|
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
|
|
78
90
|
sock.settimeout(self._socket_timeout)
|
|
79
|
-
sock.
|
|
80
|
-
sock.
|
|
91
|
+
sock.connect(self._socket_address)
|
|
92
|
+
sock.send(self._packet)
|
|
93
|
+
sock.recv_into(self._packet)
|
|
81
94
|
# Get the time in the context to minimize the difference between it and receiving
|
|
82
95
|
# the packet.
|
|
83
96
|
destination = time.monotonic_ns()
|
|
84
97
|
poll = struct.unpack_from("!B", self._packet, offset=2)[0]
|
|
85
98
|
self.next_sync = destination + (2**poll) * 1_000_000_000
|
|
86
|
-
seconds = struct.unpack_from(
|
|
87
|
-
"!I", self._packet, offset=len(self._packet) - 8
|
|
88
|
-
)[0]
|
|
99
|
+
seconds = struct.unpack_from("!I", self._packet, offset=PACKET_SIZE - 8)[0]
|
|
89
100
|
self._monotonic_start = (
|
|
90
101
|
seconds
|
|
91
102
|
+ self._tz_offset
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
|
|
2
|
+
# SPDX-FileCopyrightText: 2024 anecdata for Adafruit Industries
|
|
3
|
+
#
|
|
4
|
+
# SPDX-License-Identifier: Unlicense
|
|
5
|
+
|
|
6
|
+
"""Print out time based on NTP, using connection manager"""
|
|
7
|
+
|
|
8
|
+
import adafruit_connection_manager
|
|
9
|
+
import adafruit_ntp
|
|
10
|
+
|
|
11
|
+
# determine which radio is available
|
|
12
|
+
try:
|
|
13
|
+
import wifi
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
# adjust method to get credentials as necessary...
|
|
17
|
+
wifi_ssid = os.getenv("CIRCUITPY_WIFI_SSID")
|
|
18
|
+
wifi_password = os.getenv("CIRCUITPY_WIFI_PASSWORD")
|
|
19
|
+
radio = wifi.radio
|
|
20
|
+
while not radio.connected:
|
|
21
|
+
radio.connect(wifi_ssid, wifi_password)
|
|
22
|
+
except ImportError:
|
|
23
|
+
import board
|
|
24
|
+
from digitalio import DigitalInOut
|
|
25
|
+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
|
|
26
|
+
|
|
27
|
+
# adjust with busio.SPI() as necessary...
|
|
28
|
+
spi = board.SPI()
|
|
29
|
+
# adjust pin for the specific board...
|
|
30
|
+
eth_cs = DigitalInOut(board.D10)
|
|
31
|
+
radio = WIZNET5K(spi, eth_cs)
|
|
32
|
+
|
|
33
|
+
# get the socket pool from connection manager
|
|
34
|
+
socket = adafruit_connection_manager.get_radio_socketpool(radio)
|
|
35
|
+
|
|
36
|
+
# adjust tz_offset for locale...
|
|
37
|
+
ntp = adafruit_ntp.NTP(socket, tz_offset=-5)
|
|
38
|
+
|
|
39
|
+
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.0
|
|
15
|
+
version = "3.1.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.0.12 → adafruit_circuitpython_ntp-3.1.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.0.12 → adafruit_circuitpython_ntp-3.1.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.0.12 → adafruit_circuitpython_ntp-3.1.0}/LICENSES/CC-BY-4.0.txt
RENAMED
|
File without changes
|
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/LICENSES/Unlicense.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.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.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/examples.rst.license
RENAMED
|
File without changes
|
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/index.rst.license
RENAMED
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/docs/requirements.txt
RENAMED
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/examples/ntp_cpython.py
RENAMED
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/examples/ntp_set_rtc.py
RENAMED
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/examples/ntp_simpletest.py
RENAMED
|
File without changes
|
{adafruit-circuitpython-ntp-3.0.12 → adafruit_circuitpython_ntp-3.1.0}/optional_requirements.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|