Skip to content

Commit b3f7273

Browse files
committed
Add retrying get_time()
This way it will work with the current version of the ESP32SPI library.
1 parent a71a9c1 commit b3f7273

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

adafruit_gc_iot_core.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,19 @@ def generate_jwt(self, ttl=43200, algo="RS256"):
354354
self.logger.debug("Generating JWT...")
355355

356356
if self._esp is not None:
357-
rtc.RTC().datetime = time.localtime(self._esp.get_time()[0])
358-
else:
359-
if self.logger:
360-
self.logger.info(
361-
"No self._esp instance found, assuming RTC has been previously set"
362-
)
357+
# get_time will raise ValueError if the time isn't available yet so loop until
358+
# it works.
359+
now_utc = None
360+
while now_utc is None:
361+
try:
362+
now_utc = time.localtime(self._esp.get_time()[0])
363+
except ValueError:
364+
pass
365+
rtc.RTC().datetime = now_utc
366+
elif self.logger:
367+
self.logger.info(
368+
"No self._esp instance found, assuming RTC has been previously set"
369+
)
363370

364371
claims = {
365372
# The time that the token was issued at

0 commit comments

Comments
 (0)