File tree Expand file tree Collapse file tree 2 files changed +20
-16
lines changed
PyPortal_Azure_Plant_Monitor Expand file tree Collapse file tree 2 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 2020from adafruit_esp32spi import adafruit_esp32spi , adafruit_esp32spi_wifimanager
2121import adafruit_esp32spi .adafruit_esp32spi_socket as socket
2222import neopixel
23- from adafruit_ntp import NTP
23+ import rtc
2424from adafruit_azureiot import IoTCentralDevice
2525from adafruit_seesaw .seesaw import Seesaw
2626
5252print ("WiFi connected!" )
5353
5454# Time setup, needed to authenticate with Azure IoT Central
55- ntp = NTP (esp )
56- while not ntp .valid_time :
57- print ("Failed to obtain time, retrying in 5 seconds..." )
58- time .sleep (5 )
59- ntp .set_time ()
55+ # get_time will raise ValueError if the time isn't available yet so loop until
56+ # it works.
57+ now_utc = None
58+ while now_utc is None :
59+ try :
60+ now_utc = time .localtime (esp .get_time ()[0 ])
61+ except ValueError :
62+ pass
63+ rtc .RTC ().datetime = now_utc
6064
6165# Soil Sensor Setup
6266i2c_bus = busio .I2C (board .SCL , board .SDA )
Original file line number Diff line number Diff line change 1616from adafruit_progressbar .progressbar import ProgressBar
1717from adafruit_display_text .label import Label
1818from adafruit_esp32spi import adafruit_esp32spi
19- from adafruit_ntp import NTP
2019from adafruit_pyportal import PyPortal
20+ import rtc
2121
2222
2323# Background Color
@@ -207,15 +207,15 @@ def display_otp_key(secret_name, secret_otp):
207207
208208print ("Connected to " , secrets ['ssid' ])
209209
210- # Initialize the NTP object
211- ntp = NTP ( esp )
212-
213- # Fetch and set the microcontroller's current UTC time
214- # keep retrying until a valid time is returned
215- while not ntp . valid_time :
216- ntp . set_time ()
217- print ( "Could not obtain NTP, re-fetching in 5 seconds..." )
218- time . sleep ( 5 )
210+ # get_time will raise ValueError if the time isn't available yet so loop until
211+ # it works.
212+ now_utc = None
213+ while now_utc is None :
214+ try :
215+ now_utc = time . localtime ( esp . get_time ()[ 0 ])
216+ except ValueError :
217+ pass
218+ rtc . RTC (). datetime = now_utc
219219
220220# Get the current time in seconds since Jan 1, 1970
221221t = time .time ()
You can’t perform that action at this time.
0 commit comments