Compare commits

...

2 Commits

Author SHA1 Message Date
Paco Hope 4ff4f3f122 Resolved time issues 2023-12-01 08:52:43 -05:00
Paco Hope 156776f33f added a few more libraries 2023-12-01 08:52:26 -05:00
2 changed files with 34 additions and 16 deletions

View File

@ -28,6 +28,11 @@ These are all web sites, videos, and references I used when putting it together.
- I pulled the Wifi connection code from [RTC Clock Demo](https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/inky_frame/inky_frame_rtc_demo.py)
- I couldn't find any examples or documentation for how to use [pngdec](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/pngdec), which is the library for decoding and displaying PNG images. Luckily, it works a lot like [jpegdec](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/jpegdec) and so I used the same APIs and it worked.
## Home Assistant
* [HACS](https://hacs.xyz/): extra customisation framework that basically all Home Assistant users should have
* [Kiosk Mode](https://github.com/maykar/kiosk-mode): installs a "kiosk" mode of a Lovelace dashboard that hides the menu bars and stuff. Perfect for this application.
## Hass Screen Saver Kindle
- The [main repository](https://github.com/sibbl/hass-lovelace-kindle-screensaver/tree/main)

View File

@ -21,6 +21,7 @@ from urllib import urequest
from machine import Pin, SPI
from network_manager import NetworkManager
import time
import ntptime
import inky_frame
import pngdec
import gc
@ -31,14 +32,15 @@ import inky_frame
import uasyncio
global graphics
def display_image(j, CONFIG.FILENAME):
def display_image(j):
# Open the PNG file
j.open_file(CONFIG.FILENAME)
# Decode the PNG
j.decode()
# write the date/time at the top
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time())
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
graphics.set_pen(0)
graphics.set_font('sans')
# display.text(text, x, y, wordwrap, scale, angle, spacing)
@ -55,7 +57,7 @@ def show_error(text,y):
graphics.text(text, 5, 16 + HEIGHT, 400, 2)
gc.collect()
def fetch(url):
def fetch():
""" Fetch the image, store it onboard.
Returns False at first error.
Returns True only if everything succeeds.
@ -74,29 +76,40 @@ def fetch(url):
return False
inky_frame.button_b.led_off()
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time())
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
print(f"{hour:02}:{minute:02} {year}-{month}-{day}")
count = 0
if year < 2023:
# blink b when we are setting the time
inky_frame.button_b.led_on()
inky_frame.set_time() # set time from network
inky_frame.button_b.led_off()
# blink d when we are setting the time
inky_frame.button_d.led_on()
ntptime.host = '0.us.pool.ntp.org'
while count < 5:
try:
inky_frame.set_time() # set time from network
except OSError as e:
print( "x", end="" )
count += 1
inky_frame.button_d.led_off()
tz_seconds = (CONFIG.TZ_OFFSET * 3600)
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)
if count >= 5:
# turn on E to indicate error. gets turned off later.
inky_frame.button_e.led_on()
year, month, day, hour, minute, second, dow, _ = time.gmtime(time.time() + tz_seconds)
# don't bother updating before 06:00 or after 23:00
if hour < 5 or hour > 22:
print("no need to fetch")
print(f"hour {hour:02}, no need to fetch")
return False
del year, month, day, hour, minute, second, tz_seconds
print( "fetching " + url )
del year, month, day, hour, minute, second, tz_seconds, count
print( "fetching " + CONFIG.IMG_URL )
inky_frame.button_c.led_on()
try:
# Grab the image
socket = urequest.urlopen(url)
socket = urequest.urlopen(CONFIG.IMG_URL)
gc.collect()
except OSError as e:
print("Unable open URL. OSErr: ")
@ -161,7 +174,7 @@ while True:
mount_sd()
gc.collect()
inky_frame.button_a.led_off()
if fetch(CONFIG.IMG_URL):
if fetch():
gc.collect()
inky_frame.button_e.led_on()
@ -171,7 +184,7 @@ while True:
# Create a new PNG decoder for our PicoGraphics
j = pngdec.PNG(graphics)
display_image(j, CONFIG.FILENAME)
display_image(j)
# Display the result
graphics.update()