Compare commits

...

2 Commits

Author SHA1 Message Date
Paco Hope 19ed82d69a moved variables to global config 2023-11-30 22:05:29 -05:00
Paco Hope 59596c4e9f rename 2023-11-30 22:05:16 -05:00
2 changed files with 33 additions and 24 deletions

21
CONFIG.py Normal file
View File

@ -0,0 +1,21 @@
# this is just python syntax.
# Edit this file and enter the network name for your Wifi in SSID
# Enter the password for your Wifi network in the PSK
# Set the COUNTRY to the country code of your local country (yes, this matters!)
SSID = "Example_Network"
PSK = "Example_Password"
COUNTRY = "US" # Change to your local two-letter ISO 3166-1 country code
# URL that has the image
IMG_URL = "http://home.example.com:8123/local/image.png"
# Length of time between updates in minutes.
# Frequent updates will reduce battery life!
UPDATE_INTERVAL = 60
# 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

View File

@ -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)