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