Use ESP32SPI directly instead of NTP
The NTP library is changing to support native sockets and this API will break.
This commit is contained in:
parent
b2cf4c0888
commit
e0c283cf66
2 changed files with 20 additions and 16 deletions
|
|
@ -20,7 +20,7 @@ from digitalio import DigitalInOut
|
|||
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
|
||||
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
|
||||
import neopixel
|
||||
from adafruit_ntp import NTP
|
||||
import rtc
|
||||
from adafruit_azureiot import IoTCentralDevice
|
||||
from adafruit_seesaw.seesaw import Seesaw
|
||||
|
||||
|
|
@ -52,11 +52,15 @@ wifi.connect()
|
|||
print("WiFi connected!")
|
||||
|
||||
# Time setup, needed to authenticate with Azure IoT Central
|
||||
ntp = NTP(esp)
|
||||
while not ntp.valid_time:
|
||||
print("Failed to obtain time, retrying in 5 seconds...")
|
||||
time.sleep(5)
|
||||
ntp.set_time()
|
||||
# get_time will raise ValueError if the time isn't available yet so loop until
|
||||
# it works.
|
||||
now_utc = None
|
||||
while now_utc is None:
|
||||
try:
|
||||
now_utc = time.localtime(esp.get_time()[0])
|
||||
except ValueError:
|
||||
pass
|
||||
rtc.RTC().datetime = now_utc
|
||||
|
||||
# Soil Sensor Setup
|
||||
i2c_bus = busio.I2C(board.SCL, board.SDA)
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ from adafruit_button import Button
|
|||
from adafruit_progressbar.progressbar import ProgressBar
|
||||
from adafruit_display_text.label import Label
|
||||
from adafruit_esp32spi import adafruit_esp32spi
|
||||
from adafruit_ntp import NTP
|
||||
from adafruit_pyportal import PyPortal
|
||||
import rtc
|
||||
|
||||
|
||||
# Background Color
|
||||
|
|
@ -207,15 +207,15 @@ while not esp.is_connected:
|
|||
|
||||
print("Connected to ", secrets['ssid'])
|
||||
|
||||
# Initialize the NTP object
|
||||
ntp = NTP(esp)
|
||||
|
||||
# Fetch and set the microcontroller's current UTC time
|
||||
# keep retrying until a valid time is returned
|
||||
while not ntp.valid_time:
|
||||
ntp.set_time()
|
||||
print("Could not obtain NTP, re-fetching in 5 seconds...")
|
||||
time.sleep(5)
|
||||
# get_time will raise ValueError if the time isn't available yet so loop until
|
||||
# it works.
|
||||
now_utc = None
|
||||
while now_utc is None:
|
||||
try:
|
||||
now_utc = time.localtime(esp.get_time()[0])
|
||||
except ValueError:
|
||||
pass
|
||||
rtc.RTC().datetime = now_utc
|
||||
|
||||
# Get the current time in seconds since Jan 1, 1970
|
||||
t = time.time()
|
||||
|
|
|
|||
Loading…
Reference in a new issue