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 20
20
from adafruit_esp32spi import adafruit_esp32spi , adafruit_esp32spi_wifimanager
21
21
import adafruit_esp32spi .adafruit_esp32spi_socket as socket
22
22
import neopixel
23
- from adafruit_ntp import NTP
23
+ import rtc
24
24
from adafruit_azureiot import IoTCentralDevice
25
25
from adafruit_seesaw .seesaw import Seesaw
26
26
52
52
print ("WiFi connected!" )
53
53
54
54
# 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
60
64
61
65
# Soil Sensor Setup
62
66
i2c_bus = busio .I2C (board .SCL , board .SDA )
Original file line number Diff line number Diff line change 16
16
from adafruit_progressbar .progressbar import ProgressBar
17
17
from adafruit_display_text .label import Label
18
18
from adafruit_esp32spi import adafruit_esp32spi
19
- from adafruit_ntp import NTP
20
19
from adafruit_pyportal import PyPortal
20
+ import rtc
21
21
22
22
23
23
# Background Color
@@ -207,15 +207,15 @@ def display_otp_key(secret_name, secret_otp):
207
207
208
208
print ("Connected to " , secrets ['ssid' ])
209
209
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
219
219
220
220
# Get the current time in seconds since Jan 1, 1970
221
221
t = time .time ()
You can’t perform that action at this time.
0 commit comments