From 52baaa8f702986fa0c8dfd25ea089fa9caa16504 Mon Sep 17 00:00:00 2001 From: viewit Date: Sun, 2 Aug 2026 15:59:41 +0200 Subject: [PATCH] feat(debug): add MQTT_RAW_LOG env switch for unfiltered RX logging Logs every incoming MQTT message on INFO regardless of topic, including dedup'd duplicates and topics with no registered callback - useful for capturing printer behavior the bridge doesn't normally surface without needing to know the topic name in advance (the existing wildcard subscribe already receives everything, this just makes it visible). --- kobrax_client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kobrax_client.py b/kobrax_client.py index a46a0fd..86cddc2 100644 --- a/kobrax_client.py +++ b/kobrax_client.py @@ -144,6 +144,11 @@ class KobraXClient: # Dedup: last hash per topic suffix to suppress repeated identical messages self._last_rx_hash: dict[str, str] = {} + # Debug switch (MQTT_RAW_LOG=1): logs every RX message unfiltered on + # INFO, including dedup'd duplicates and topics with no registered + # callback - for capturing printer behavior the bridge doesn't + # normally surface (e.g. reverse-engineering a rejected command). + self._raw_log = os.environ.get("MQTT_RAW_LOG", "").strip().lower() in ("1", "true", "yes") # Fields that change every tick and should be stripped before dedup-hashing _VOLATILE = {"timestamp", "msgid", "progress", "curr_layer", "curr_nozzle_temp", "curr_hotbed_temp", @@ -422,6 +427,9 @@ class KobraXClient: def _dispatch(self, topic: str, payload: dict): suffix = "/".join(topic.split("/")[-2:]) + if self._raw_log: + log.info("RX [raw] %s %s", topic, json.dumps(payload, ensure_ascii=False)) + # Structured RX log with dedup suppression h = self._dedup_hash(suffix, payload) is_dup = self._last_rx_hash.get(suffix) == h