From 1c47ea7f0caca2b5bf55b9e138acd3eb31f7f36c Mon Sep 17 00:00:00 2001 From: brentru Date: Wed, 25 Sep 2019 10:49:06 -0400 Subject: [PATCH 1/2] patching overflow error --- adafruit_ntp.py | 17 +++++++++++------ examples/ntp_simpletest.py | 6 +++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/adafruit_ntp.py b/adafruit_ntp.py index 05e056d..7165dd9 100644 --- a/adafruit_ntp.py +++ b/adafruit_ntp.py @@ -42,26 +42,31 @@ import time import rtc -__version__ = "0.0.0-auto.0" +__version__ = "1.0.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NTP.git" class NTP: """Network Time Protocol (NTP) helper module for CircuitPython. This module does not handle daylight savings or local time. - :param adafruit_esp32spi esp: ESP32SPI Module + :param adafruit_esp32spi esp: ESP32SPI object. """ def __init__(self, esp): # Verify ESP32SPI module if "ESP_SPIcontrol" in str(type(esp)): self._esp = esp else: - raise TypeError("Provided esp is not an ESP_SPIcontrol object") + raise TypeError("Provided object is not an ESP_SPIcontrol object.") + self.valid_time = False def set_time(self): """Fetches and sets the microcontroller's current time in seconds since since Jan 1, 1970. """ - now = self._esp.get_time() - now = time.localtime(now[0]) - rtc.RTC().datetime = now + try: + now = self._esp.get_time() + now = time.localtime(now[0]) + rtc.RTC().datetime = now + self.valid_time = True + except ValueError: + return diff --git a/examples/ntp_simpletest.py b/examples/ntp_simpletest.py index 869e85d..3d7dad9 100644 --- a/examples/ntp_simpletest.py +++ b/examples/ntp_simpletest.py @@ -30,7 +30,11 @@ ntp = NTP(esp) # Fetch and set the microcontroller's current UTC time -ntp.set_time() +# keep retrying until a valid time is returned +while not ntp.valid_time: + ntp.set_time() + print("Failed to obtain time, retrying in 5 seconds...") + time.sleep(5) # Get the current time in seconds since Jan 1, 1970 current_time = time.time() From 2523230fae084160d0703bc14e5fcafc4f8f6bb5 Mon Sep 17 00:00:00 2001 From: brentru Date: Wed, 25 Sep 2019 10:51:03 -0400 Subject: [PATCH 2/2] fix version to autover --- adafruit_ntp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_ntp.py b/adafruit_ntp.py index 7165dd9..14b2d77 100644 --- a/adafruit_ntp.py +++ b/adafruit_ntp.py @@ -42,7 +42,7 @@ import time import rtc -__version__ = "1.0.0" +__version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NTP.git" class NTP: