feat: add logging for raw protobuf messages as JSON on receive and send

This commit is contained in:
sh4un
2026-01-29 21:04:48 -05:00
parent 58c30b9f47
commit 80546a0936

View File

@@ -1,3 +1,4 @@
from google.protobuf.json_format import MessageToJson
# ammb/meshtastic_handler.py
"""
Handles all interactions with the Meshtastic device and network.
@@ -186,6 +187,14 @@ class MeshtasticHandler:
def _on_meshtastic_receive(self, packet: Dict[str, Any], interface: Any, weak=None):
try:
# Log raw protobuf as JSON if available
try:
if hasattr(interface, 'lastPacket') and interface.lastPacket:
# lastPacket is a protobuf object
json_str = MessageToJson(interface.lastPacket)
self.logger.debug("Raw protobuf (incoming) as JSON: %s", json_str)
except Exception as e:
self.logger.debug("Could not convert incoming protobuf to JSON: %s", e)
if not packet or "from" not in packet:
return
@@ -344,6 +353,15 @@ class MeshtasticHandler:
log_payload,
)
# Log outgoing protobuf as JSON if possible
try:
if self.interface and hasattr(self.interface, 'myInfo') and self.interface.myInfo:
# myInfo is a protobuf object
json_str = MessageToJson(self.interface.myInfo)
self.logger.debug("Raw protobuf (outgoing) as JSON: %s", json_str)
except Exception as e:
self.logger.debug("Could not convert outgoing protobuf to JSON: %s", e)
with self._lock:
if self.interface and self._is_connected.is_set():
try: