Merge pull request #10 from AkitaEngineering/examples/config-templates

feat: add logging for raw protobuf messages as JSON on receive and send
This commit is contained in:
sh4un authored and GitHub committed 2026-01-29 21:07:34 -05:00
commit d3a89eb859
1 file changed
+18
+18
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: