diff --git a/inky-lovelace.py b/inky-lovelace.py index 80ddb6f..6522c5c 100644 --- a/inky-lovelace.py +++ b/inky-lovelace.py @@ -26,26 +26,14 @@ import pngdec import gc import sdcard import os -import WIFI_CONFIG +import CONFIG import inky_frame import uasyncio -global UPDATE_INTERVAL, IMG_URL, FILENAME, graphics, tz_offset +global graphics -# Length of time between updates in minutes. -# Frequent updates will reduce battery life! -UPDATE_INTERVAL = 60 - -# URL that has the image -IMG_URL = "http://hub.home.paco.to/" -# IMG_URL = "https://house.paco.to/local/frame.png" -# Filename on the SD card for the image. Probably doesn't need changing. -FILENAME = "/sd/frame.png" -# tz_offset is hours from GMT. E.g., US PST is -7 (UTC-07:00) and CEST (Paris) is 1 (UTC+01:00) -tz_offset = -5 - -def display_image(j, filename): +def display_image(j, CONFIG.FILENAME): # Open the PNG file - j.open_file(filename) + j.open_file(CONFIG.FILENAME) # Decode the PNG j.decode() @@ -74,9 +62,9 @@ def fetch(url): """ inky_frame.button_b.led_on() - network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler, client_timeout=60) + network_manager = NetworkManager(CONFIG.COUNTRY, status_handler=status_handler, client_timeout=60) try: - uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) + uasyncio.get_event_loop().run_until_complete(network_manager.client(CONFIG.SSID, CONFIG.PSK)) except RuntimeError: pass except Exception as e: @@ -95,7 +83,7 @@ def fetch(url): inky_frame.set_time() # set time from network inky_frame.button_b.led_off() - tz_seconds = (tz_offset * 3600) + tz_seconds = (CONFIG.TZ_OFFSET * 3600) year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds) # don't bother updating before 06:00 or after 23:00 @@ -117,12 +105,12 @@ def fetch(url): print("other exception") print(e) return False - os.remove(FILENAME) + os.remove(CONFIG.FILENAME) inky_frame.button_c.led_off() inky_frame.button_d.led_on() try: data = bytearray(1024) - with open(FILENAME, "wb+") as f: + with open(CONFIG.FILENAME, "wb+") as f: while True: if socket.readinto(data) == 0: break @@ -173,7 +161,7 @@ while True: mount_sd() gc.collect() inky_frame.button_a.led_off() - if fetch(IMG_URL): + if fetch(CONFIG.IMG_URL): gc.collect() inky_frame.button_e.led_on() @@ -183,7 +171,7 @@ while True: # Create a new PNG decoder for our PicoGraphics j = pngdec.PNG(graphics) - display_image(j, FILENAME) + display_image(j, CONFIG.FILENAME) # Display the result graphics.update() @@ -195,5 +183,5 @@ while True: inky_frame.button_c.led_off() inky_frame.button_d.led_off() inky_frame.button_e.led_off() - inky_frame.sleep_for(UPDATE_INTERVAL) + inky_frame.sleep_for(CONFIG.UPDATE_INTERVAL)