MQTT status fix

This commit is contained in:
2026-02-12 08:14:45 +00:00
parent ae622aa5bd
commit 6a41765603

View File

@@ -30,24 +30,21 @@ def print_label(image, printer=PRINTER_DEVICE, model=PRINTER_MODEL, label=LABEL_
"""Print the label directly using brother_ql module""" """Print the label directly using brother_ql module"""
import os import os
try: # Check if printer device exists
# Check if printer device exists if not os.path.exists(printer):
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.")
raise Exception(f"Printer device {printer} not found. Make sure the printer is powered on and connected via USB.")
qlr = BrotherQLRaster(model)
qlr = BrotherQLRaster(model) qlr.exception_on_warning = True
qlr.exception_on_warning = True
# Convert the PIL image to instructions
# Convert the PIL image to instructions instructions = convert(qlr=qlr, images=[image], label=label, cut=True)
instructions = convert(qlr=qlr, images=[image], label=label, cut=True)
# Send to printer using linux_kernel backend
# Send to printer using linux_kernel backend print(f"Sending to printer: {printer}")
print(f"Sending to printer: {printer}") status = send(instructions=instructions, printer_identifier=f"file://{printer}", backend_identifier='linux_kernel', blocking=True)
status = send(instructions=instructions, printer_identifier=f"file://{printer}", backend_identifier='linux_kernel', blocking=True)
return status
return status
except Exception as e:
raise e
def on_connect(client, userdata, flags, rc): def on_connect(client, userdata, flags, rc):
print(f"Connected to MQTT broker at {MQTT_HOST}:{MQTT_PORT} with result code {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) print(error_msg)
error_details = {"status": "error", "job_id": job_id, "error": error_msg, "topic": msg.topic} error_details = {"status": "error", "job_id": job_id, "error": error_msg, "topic": msg.topic}
client.publish(MQTT_TOPIC_PUB_STATUS, json.dumps(error_details)) 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)}" error_msg = f"Error processing message: {str(e)}"
print(error_msg) print(error_msg)
error_details = {"status": "error", "job_id": job_id, "error": error_msg, "original_payload": raw_payload} 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)) client.publish(MQTT_TOPIC_PUB_STATUS, json.dumps(error_details))
send_webhook("processing_error", error_details)
def heartbeat(client): def heartbeat(client):
while True: while True:
try: try: