diff --git a/adafruit_gc_iot_core.py b/adafruit_gc_iot_core.py index 91b0c10..917b6e8 100644 --- a/adafruit_gc_iot_core.py +++ b/adafruit_gc_iot_core.py @@ -30,6 +30,7 @@ import adafruit_logging as logging from adafruit_jwt import JWT +import rtc __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_GC_IOT_Core.git" @@ -353,19 +354,19 @@ def generate_jwt(self, ttl=43200, algo="RS256"): self.logger.debug("Generating JWT...") if self._esp is not None: - # Not all boards have ESP access easily (eg: featherS2). - # If we pass in a False or None in init, lets - # assume that we've handled setting the RTC outside of here - # pylint: disable=import-outside-toplevel - import adafruit_ntp as NTP - - ntp = NTP.NTP(self._esp) - ntp.set_time() - else: - if self.logger: - self.logger.info( - "No self._esp instance found, assuming RTC has been previously set" - ) + # 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(self._esp.get_time()[0]) + except ValueError: + pass + rtc.RTC().datetime = now_utc + elif self.logger: + self.logger.info( + "No self._esp instance found, assuming RTC has been previously set" + ) claims = { # The time that the token was issued at diff --git a/docs/conf.py b/docs/conf.py index d345a8b..e94d041 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["adafruit_logging", "adafruit_jwt", "adafruit_ntp", "rtc"] +autodoc_mock_imports = ["adafruit_logging", "adafruit_jwt", "rtc"] intersphinx_mapping = { "python": ("https://docs.python.org/3", None),