From 6a4176560338b7ac55f437c7cc57368fbe705293 Mon Sep 17 00:00:00 2001 From: James Pattinson Date: Thu, 12 Feb 2026 08:14:45 +0000 Subject: [PATCH] MQTT status fix --- client.py | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/client.py b/client.py index b7c5e3b..931b718 100644 --- a/client.py +++ b/client.py @@ -30,24 +30,21 @@ def print_label(image, printer=PRINTER_DEVICE, model=PRINTER_MODEL, label=LABEL_ """Print the label directly using brother_ql module""" import os - try: - # Check if printer device exists - if not os.path.exists(printer): - raise Exception(f"Printer device {printer} not found. Make sure the printer is powered on and connected via USB.") - - qlr = BrotherQLRaster(model) - qlr.exception_on_warning = True - - # Convert the PIL image to instructions - instructions = convert(qlr=qlr, images=[image], label=label, cut=True) - - # Send to printer using linux_kernel backend - print(f"Sending to printer: {printer}") - status = send(instructions=instructions, printer_identifier=f"file://{printer}", backend_identifier='linux_kernel', blocking=True) - - return status - except Exception as e: - raise e + # Check if printer device exists + if not os.path.exists(printer): + raise Exception(f"Printer device {printer} not found. Make sure the printer is powered on and connected via USB.") + + qlr = BrotherQLRaster(model) + qlr.exception_on_warning = True + + # Convert the PIL image to instructions + instructions = convert(qlr=qlr, images=[image], label=label, cut=True) + + # Send to printer using linux_kernel backend + print(f"Sending to printer: {printer}") + status = send(instructions=instructions, printer_identifier=f"file://{printer}", backend_identifier='linux_kernel', blocking=True) + + return status def on_connect(client, userdata, flags, rc): print(f"Connected to MQTT broker at {MQTT_HOST}:{MQTT_PORT} with result code {rc}") @@ -150,12 +147,12 @@ def on_message(client, userdata, msg): print(error_msg) error_details = {"status": "error", "job_id": job_id, "error": error_msg, "topic": msg.topic} client.publish(MQTT_TOPIC_PUB_STATUS, json.dumps(error_details)) - send_webhook("parse_error", error_details) + except Exception as e: error_msg = f"Error processing message: {str(e)}" print(error_msg) error_details = {"status": "error", "job_id": job_id, "error": error_msg, "original_payload": raw_payload} client.publish(MQTT_TOPIC_PUB_STATUS, json.dumps(error_details)) - send_webhook("processing_error", error_details) + def heartbeat(client): while True: try: