diff --git a/README.md b/README.md index 81a209c..cd9fcff 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,9 @@ The following `deck.fs` functions are direct aliases to the corresponding `os` c - `env` = `getenv` = `os.getenv` - `rnd` = `urandom` = `os.urandom` -### `deck.hwinfo` (WIP) +### `deck.hwinfo` -Various hardware information. +Various hardware information. May be expanded in the future. Exports the following functions: @@ -120,6 +120,7 @@ Exported functions: - `ssl_context()`: get the default SSL context for wrapping in a raw socket - `init_socket()`: return the active reference to the `socket` library - `init_requests()`: return the active reference to the `requests` library +- `init_ntp(tz=0)`: return an NTP time client instance (use the `.datetime` property of the instance to access current time and the `tz` parameter to specify the timezone offset) A normal flow for instantiating a Requests library looks like this: @@ -258,7 +259,7 @@ The foundational module set is going to at least include high-level capabilities - date and time informaion (done), - file system manipulation (done), - text viewing and editing (done), -- device information collection (partially done), +- device information collection (done), - chat UI creation (done). After all this is implemented, future phases may also include device-specific features like GPS, graphics, sound and touchscreen input. diff --git a/deck/net.py b/deck/net.py index 0b4c5ab..19d1829 100644 --- a/deck/net.py +++ b/deck/net.py @@ -12,9 +12,11 @@ # # Created by Luxferre in 2025, released into public domain -import os, time # standard modules -import wifi # CircuitPython builtins -import adafruit_connection_manager, adafruit_requests # Adafruit Bundle libs +import os, time # standard modules +import wifi # CircuitPython builtins +# Adafruit Bundle libs +import adafruit_connection_manager +import adafruit_requests, adafruit_ntp def wifi_connect(ssid=None, password=None): ''' @@ -71,3 +73,8 @@ def init_requests(): 'Instantiate a Requests library' return adafruit_requests.Session(init_socket(), ssl_context()) +def init_ntp(tz=0): + 'Instantiate an NTP time client' + pool = init_socket() + return adafruit_ntp.NTP(pool, tz_offset=tz, cache_seconds=3600) + diff --git a/requirements.txt b/requirements.txt index bd340a3..dd5215d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ adafruit_connection_manager>=3.1.6 adafruit_requests>=4.1.15 -adafruit_bus_device>=5.2.14 adafruit_datetime>=1.4.4 +adafruit_ntp>=3.3.5 +adafruit_bus_device>=5.2.14