Compare commits
No commits in common. "19ed82d69ad02418f89cb3874f1cb79a576ff6f9" and "d22a792984394b23560863cfb14c4d5d9752e33a" have entirely different histories.
19ed82d69a
...
d22a792984
21
CONFIG.py
21
CONFIG.py
|
@ -1,21 +0,0 @@
|
|||
# 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
|
|
@ -26,14 +26,26 @@ import pngdec
|
|||
import gc
|
||||
import sdcard
|
||||
import os
|
||||
import CONFIG
|
||||
import WIFI_CONFIG
|
||||
import inky_frame
|
||||
import uasyncio
|
||||
global graphics
|
||||
global UPDATE_INTERVAL, IMG_URL, FILENAME, graphics, tz_offset
|
||||
|
||||
def display_image(j, CONFIG.FILENAME):
|
||||
# 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):
|
||||
# Open the PNG file
|
||||
j.open_file(CONFIG.FILENAME)
|
||||
j.open_file(filename)
|
||||
# Decode the PNG
|
||||
j.decode()
|
||||
|
||||
|
@ -62,9 +74,9 @@ def fetch(url):
|
|||
"""
|
||||
|
||||
inky_frame.button_b.led_on()
|
||||
network_manager = NetworkManager(CONFIG.COUNTRY, status_handler=status_handler, client_timeout=60)
|
||||
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler, client_timeout=60)
|
||||
try:
|
||||
uasyncio.get_event_loop().run_until_complete(network_manager.client(CONFIG.SSID, CONFIG.PSK))
|
||||
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
|
||||
except RuntimeError:
|
||||
pass
|
||||
except Exception as e:
|
||||
|
@ -83,7 +95,7 @@ def fetch(url):
|
|||
inky_frame.set_time() # set time from network
|
||||
inky_frame.button_b.led_off()
|
||||
|
||||
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
|
||||
tz_seconds = (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
|
||||
|
@ -105,12 +117,12 @@ def fetch(url):
|
|||
print("other exception")
|
||||
print(e)
|
||||
return False
|
||||
os.remove(CONFIG.FILENAME)
|
||||
os.remove(FILENAME)
|
||||
inky_frame.button_c.led_off()
|
||||
inky_frame.button_d.led_on()
|
||||
try:
|
||||
data = bytearray(1024)
|
||||
with open(CONFIG.FILENAME, "wb+") as f:
|
||||
with open(FILENAME, "wb+") as f:
|
||||
while True:
|
||||
if socket.readinto(data) == 0:
|
||||
break
|
||||
|
@ -161,7 +173,7 @@ while True:
|
|||
mount_sd()
|
||||
gc.collect()
|
||||
inky_frame.button_a.led_off()
|
||||
if fetch(CONFIG.IMG_URL):
|
||||
if fetch(IMG_URL):
|
||||
gc.collect()
|
||||
inky_frame.button_e.led_on()
|
||||
|
||||
|
@ -171,7 +183,7 @@ while True:
|
|||
# Create a new PNG decoder for our PicoGraphics
|
||||
j = pngdec.PNG(graphics)
|
||||
|
||||
display_image(j, CONFIG.FILENAME)
|
||||
display_image(j, FILENAME)
|
||||
# Display the result
|
||||
graphics.update()
|
||||
|
||||
|
@ -183,5 +195,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(CONFIG.UPDATE_INTERVAL)
|
||||
inky_frame.sleep_for(UPDATE_INTERVAL)
|
||||
|
||||
|
|
Loading…
Reference in New Issue