Skip to content

Stop using NTP library and get time directly #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions adafruit_gc_iot_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down