Pyportal timezone error

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Broeng
 
Posts: 2
Joined: Fri Dec 07, 2018 8:12 pm

Pyportal timezone error

Post by Broeng »

I was using a slightly modified version of the countdown from https://learn.adafruit.com/pyportal-eve ... k?view=all. The only real changes were the background image and the position of the days, hours, and mins on the screen. One day it just stopped. I have reload circuit python and the original code. I continue to get the below error.

Code: Select all

Getting time from internet!
Getting time for timezone America/New_York
Some error occured, retrying! - Expected 01 but got 00
The only thing I have notice is the issue links back to adafruit_pyportal.mpy
thanks

User avatar
johnpark
 
Posts: 985
Joined: Wed Mar 25, 2009 2:15 pm

Re: Pyportal timezone error

Post by johnpark »

Could you please post the code.py you're running?

User avatar
Broeng
 
Posts: 2
Joined: Fri Dec 07, 2018 8:12 pm

Re: Pyportal timezone error

Post by Broeng »

The only thing changed form the original code on the tutorial is the event dates and the position of the numbers. It seems to get hung up around lines 55-59, that is why I believe it is the adafruit_pyportal.mpy. I also have the time service and AdafruitIO info in secrets.py setup as expected.
Thanks

Code: Select all

"""
This example will figure out the current local time using the internet, and
then draw out a countdown clock until an event occurs!
Once the event is happening, a new graphic is shown
"""
import time
import board
from adafruit_pyportal import PyPortal
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text.label import Label

# The time of the thing!
EVENT_YEAR = 2019
EVENT_MONTH = 12
EVENT_DAY = 16
EVENT_HOUR = 15
EVENT_MINUTE = 59
# we'll make a python-friendly structure
event_time = time.struct_time((EVENT_YEAR, EVENT_MONTH, EVENT_DAY,
                               EVENT_HOUR, EVENT_MINUTE, 0,  # we don't track seconds
                               -1, -1, False))  # we dont know day of week/year or DST

# determine the current working directory
# needed so we know where to find files
cwd = ("/"+__file__).rsplit('/', 1)[0]
# Initialize the pyportal object and let us know what data to fetch and where
# to display it
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/countdown_background.bmp")

big_font = bitmap_font.load_font(cwd+"/fonts/Helvetica-Bold-36.bdf")
big_font.load_glyphs(b'0123456789') # pre-load glyphs for fast printing
event_background = cwd+"/countdown_event.bmp"

days_position = (50, 40)
hours_position = (120, 200)
minutes_position = (220, 40)
text_color = 0x000000

text_areas = []
for pos in (days_position, hours_position, minutes_position):
    textarea = Label(big_font, max_glyphs=3)
    textarea.x = pos[0]
    textarea.y = pos[1]
    textarea.color = text_color
    pyportal.splash.append(textarea)
    text_areas.append(textarea)
refresh_time = None

while True:
    # only query the online time once per hour (and on first run)
    if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
        try:
            print("Getting time from internet!")
            pyportal.get_local_time()
            refresh_time = time.monotonic()
        except RuntimeError as e:
            print("Some error occured, retrying! -", e)
            continue

    now = time.localtime()
    print("Current time:", now)
    remaining = time.mktime(event_time) - time.mktime(now)
    print("Time remaining (s):", remaining)
    if remaining < 0:
        # oh, its event time!
        pyportal.set_background(event_background)
        while True:  # that's all folks
            pass
    secs_remaining = remaining % 60
    remaining //= 60
    mins_remaining = remaining % 60
    remaining //= 60
    hours_remaining = remaining % 24
    remaining //= 24
    days_remaining = remaining
    print("%d days, %d hours, %d minutes and %s seconds" %
          (days_remaining, hours_remaining, mins_remaining, secs_remaining))
    text_areas[0].text = '{:>2}'.format(days_remaining)  # set days textarea
    text_areas[1].text = '{:>2}'.format(hours_remaining) # set hours textarea
    text_areas[2].text = '{:>2}'.format(mins_remaining)  # set minutes textarea

    # update every 10 seconds
    time.sleep(10)

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”