feat: print to discovered printer IP

print_receipt now resolves the printer by MAC via discover_printer() instead of
a hardcoded IP. Verified end-to-end: physical receipt printed to 192.168.0.184.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mortdecai
2026-06-07 13:32:49 -04:00
parent 06bc18ed31
commit 362053f8d6
+7 -2
View File
@@ -504,9 +504,14 @@ def discover_printer():
def print_receipt(raw_bytes): def print_receipt(raw_bytes):
try: try:
with socket.create_connection((PRINTER_IP, PRINTER_PORT), timeout=10) as sock: ip = discover_printer()
except Exception as e:
print(f"[!] Printer discovery failed: {e}")
return False
try:
with socket.create_connection((ip, PRINTER_PORT), timeout=10) as sock:
sock.sendall(raw_bytes) sock.sendall(raw_bytes)
print(f"✓ Receipt sent to {PRINTER_IP}:{PRINTER_PORT}") print(f"✓ Receipt sent to {ip}:{PRINTER_PORT}")
return True return True
except Exception as e: except Exception as e:
print(f"[!] Print failed: {e}") print(f"[!] Print failed: {e}")