Print images from dev too
This commit is contained in:
20
main.py
20
main.py
@@ -16,19 +16,25 @@ from aiomqtt import Client
|
||||
|
||||
VENDOR_ID = 0x0416
|
||||
PRODUCT_ID = 0x5011
|
||||
STATIC_URL = 'https://static.my.protospace.ca/'
|
||||
PROD_STATIC_URL = 'https://static.my.protospace.ca/'
|
||||
DEV_STATIC_URL = 'https://static.spaceport.dns.t0.vc/'
|
||||
PRINTER_WIDTH = 384
|
||||
|
||||
|
||||
def print_picture(filename, p):
|
||||
def print_picture(topic, filename, p):
|
||||
logging.info('New picture submitted: %s', filename)
|
||||
|
||||
if topic.startswith('dev_'):
|
||||
url = DEV_STATIC_URL
|
||||
else:
|
||||
url = PROD_STATIC_URL
|
||||
|
||||
try:
|
||||
p.hw('INIT')
|
||||
response = requests.get(STATIC_URL + filename, timeout=5)
|
||||
#p.hw('INIT')
|
||||
response = requests.get(url + filename, timeout=5)
|
||||
response.raise_for_status()
|
||||
|
||||
print('New image detected, printing...')
|
||||
logging.info('New image detected, printing...')
|
||||
last_image_content = response.content
|
||||
|
||||
img = Image.open(io.BytesIO(response.content))
|
||||
@@ -41,7 +47,7 @@ def print_picture(filename, p):
|
||||
p.cut()
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f'Error downloading image: {e}')
|
||||
logging.info(f'Error downloading image: {e}')
|
||||
|
||||
|
||||
async def process_mqtt(message, p):
|
||||
@@ -50,7 +56,7 @@ async def process_mqtt(message, p):
|
||||
logging.debug('MQTT topic: %s, message: %s', topic, text)
|
||||
|
||||
if 'spaceport/drawing/new' in topic:
|
||||
print_picture(text, p)
|
||||
print_picture(topic, text, p)
|
||||
else:
|
||||
logging.debug('Invalid topic, returning')
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user