This commit is contained in:
2025-12-30 20:53:17 -07:00
parent 6ff5f33ba1
commit e602c47808

16
main.py
View File

@@ -16,36 +16,32 @@ from aiomqtt import Client
VENDOR_ID = 0x0416
PRODUCT_ID = 0x5011
STATIC_URL = "https://static.spaceport.dns.t0.vc/"
PRINTER_WIDTH = 384 # Set to your printer's pixel width (common: 384 or 576)
STATIC_URL = 'https://static.spaceport.dns.t0.vc/'
PRINTER_WIDTH = 384
def print_picture(filename, p):
logging.info('New picture submitted: %s', filename)
try:
p.hw('INIT')
response = requests.get(STATIC_URL + filename, timeout=5)
response.raise_for_status()
print("New image detected, printing...")
print('New image detected, printing...')
last_image_content = response.content
img = Image.open(io.BytesIO(response.content))
if img.mode == 'RGBA':
bg = Image.new('RGB', img.size, (255, 255, 255))
bg.paste(img, mask=img.split()[3])
img = bg
# Convert with dithering
img = img.convert('1', dither=Image.FLOYDSTEINBERG)
# Print image
p.image(img)
p.text('\n\n\n')
p.cut()
except requests.exceptions.RequestException as e:
print(f"Error downloading image: {e}")
print(f'Error downloading image: {e}')
async def process_mqtt(message, p):