-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from anecdata/cm_multi_radio
Example using adafruit_connection_manager
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries | ||
# SPDX-FileCopyrightText: 2024 anecdata for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: Unlicense | ||
|
||
"""Print out time based on NTP, using connection manager""" | ||
|
||
import adafruit_connection_manager | ||
import adafruit_ntp | ||
|
||
# determine which radio is available | ||
try: | ||
import wifi | ||
import os | ||
|
||
# adjust method to get credentials as necessary... | ||
wifi_ssid = os.getenv("CIRCUITPY_WIFI_SSID") | ||
wifi_password = os.getenv("CIRCUITPY_WIFI_PASSWORD") | ||
radio = wifi.radio | ||
while not radio.connected: | ||
radio.connect(wifi_ssid, wifi_password) | ||
except ImportError: | ||
import board | ||
from digitalio import DigitalInOut | ||
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K | ||
|
||
# adjust with busio.SPI() as necessary... | ||
spi = board.SPI() | ||
# adjust pin for the specific board... | ||
eth_cs = DigitalInOut(board.D10) | ||
radio = WIZNET5K(spi, eth_cs) | ||
|
||
# get the socket pool from connection manager | ||
socket = adafruit_connection_manager.get_radio_socketpool(radio) | ||
|
||
# adjust tz_offset for locale... | ||
ntp = adafruit_ntp.NTP(socket, tz_offset=-5) | ||
|
||
print(ntp.datetime) |