From 7307a3c7165de323b6d49d2629d51099de41b195 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 19 May 2020 15:23:52 -0700 Subject: [PATCH] auto decode text payloads --- .vscode/launch.json | 8 ++++++++ meshtastic/__init__.py | 6 +++--- meshtastic/test.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5fe68ed..8404299 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,6 +27,14 @@ "module": "meshtastic", "justMyCode": true, "args": ["--debug", "--seriallog", "stdout"] + }, + { + "name": "meshtastic test", + "type": "python", + "request": "launch", + "module": "meshtastic", + "justMyCode": true, + "args": ["--test"] } ] } diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index ab9e19d..150be02 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -249,9 +249,9 @@ class MeshInterface: if meshPacket.decoded.HasField("data"): topic = "meshtastic.receive.data" # For text messages, we go ahead and decode the text to ascii for our users - # if asObj.decoded.data.typ == "CLEAR_TEXT": - # asObj.decoded.data.text = asObj.decoded.data.decoded.decode( - # "utf-8") + if asDict["decoded"]["data"]["typ"] == "CLEAR_TEXT": + asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode( + "utf-8") pub.sendMessage(topic, packet=asDict, interface=self) diff --git a/meshtastic/test.py b/meshtastic/test.py index a9ade1b..ed56dbd 100644 --- a/meshtastic/test.py +++ b/meshtastic/test.py @@ -56,7 +56,7 @@ def testSend(fromInterface, toInterface): toNode = toInterface.myInfo.my_node_num # FIXME, hack to test broadcast - toNode = 255 + # toNode = 255 logging.info(f"Sending test packet from {fromNode} to {toNode}") fromInterface.sendText(f"Test {testNumber}", toNode)