Suppress duplicate weight logs (only log on change)

This commit is contained in:
2026-06-07 08:56:29 +00:00
parent 207f8e0b0c
commit e4169735b1
+6 -2
View File
@@ -197,7 +197,8 @@ def main():
mqtt_connect() mqtt_connect()
lights_off() lights_off()
print("[BOOT] Система готова. Жду машину...\n") print("[BOOT] Система готова. Жду машину...
")
subprocess.run(['stty', '-F', SERIAL_PORT, 'raw', str(SERIAL_BAUD), subprocess.run(['stty', '-F', SERIAL_PORT, 'raw', str(SERIAL_BAUD),
'cs8', '-cstopb', '-parenb'], check=False) 'cs8', '-cstopb', '-parenb'], check=False)
@@ -212,6 +213,7 @@ def main():
last_weights = [] last_weights = []
buf = b"" buf = b""
go_sent_time = None go_sent_time = None
last_logged_w = None # последнее залогированное значение веса
while True: while True:
# ── Неблокирующее чтение с таймаутом 100 мс ────────────────────────── # ── Неблокирующее чтение с таймаутом 100 мс ──────────────────────────
@@ -243,7 +245,9 @@ def main():
continue continue
now = time.time() now = time.time()
print(f"[SCALE] {w:.1f} кг [{state}]") if w != last_logged_w:
print(f"[SCALE] {w:.1f} кг [{state}]")
last_logged_w = w
# ── EMPTY: нет машины ───────────────────────────────────────── # ── EMPTY: нет машины ─────────────────────────────────────────
if state == 'EMPTY': if state == 'EMPTY':