From 1548d88605420b52f416ca4acaf65bf4c10862b3 Mon Sep 17 00:00:00 2001 From: IZ1IVA <75425638+IZ1IVA@users.noreply.github.com> Date: Wed, 9 Dec 2020 10:35:25 +0100 Subject: [PATCH 1/3] Create python-cmd-guide.md Python API commands guide --- docs/python-cmd-guide.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 docs/python-cmd-guide.md diff --git a/docs/python-cmd-guide.md b/docs/python-cmd-guide.md new file mode 100644 index 0000000..9c73d5d --- /dev/null +++ b/docs/python-cmd-guide.md @@ -0,0 +1,2 @@ +# Python API commands guide + From 538c6d2b4d8fdb3d6dff200ce40947f3a53b226f Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Thu, 10 Dec 2020 20:19:08 -0500 Subject: [PATCH 2/3] add --version cli flag --- meshtastic/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index ee57f80..c3a11df 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -11,6 +11,7 @@ import pyqrcode import traceback import codecs import base64 +import pkg_resources """The command line arguments""" args = None @@ -349,6 +350,8 @@ def main(): parser.set_defaults(router=None) + parser.add_argument('--version', action='version', version=f"{pkg_resources.require('meshtastic')[0].version}") + global args args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) From 28fd3491788bf27a729648e4e694201a9175d5c2 Mon Sep 17 00:00:00 2001 From: Tim Gunter Date: Mon, 14 Dec 2020 00:33:30 -0800 Subject: [PATCH 3/3] Convert portnum strings to enum values and set UNKNOWN_APP as a string to match how protobuf provides them --- meshtastic/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 1cc8021..0602442 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -462,16 +462,20 @@ class MeshInterface: # byte array. asDict["decoded"]["data"]["payload"] = meshPacket.decoded.data.payload - # UNKNOWN_APP is the default protobuf pornum value, and therefore if not set it will not be populated at all + # UNKNOWN_APP is the default protobuf portnum value, and therefore if not set it will not be populated at all # to make API usage easier, set it to prevent confusion if not "portnum" in asDict["decoded"]["data"]: - asDict["decoded"]["data"]["portnum"] = portnums_pb2.PortNum.UNKNOWN_APP + asDict["decoded"]["data"]["portnum"] = portnums_pb2.PortNum.Name(portnums_pb2.PortNum.UNKNOWN_APP) portnum = asDict["decoded"]["data"]["portnum"] + + if isinstance(portnum, str): + portnum = portnums_pb2.PortNum.Value(portnum) + topic = f"meshtastic.receive.data.{portnum}" # For text messages, we go ahead and decode the text to ascii for our users - if asDict["decoded"]["data"]["portnum"] == portnums_pb2.PortNum.TEXT_MESSAGE_APP: + if portnum == portnums_pb2.PortNum.TEXT_MESSAGE_APP: topic = "meshtastic.receive.text" # We don't throw if the utf8 is invalid in the text message. Instead we just don't populate @@ -486,7 +490,7 @@ class MeshInterface: logging.error(f"Malformatted utf8 in text message: {ex}") # decode position protobufs and update nodedb, provide decoded version as "position" in the published msg - if asDict["decoded"]["data"]["portnum"] == portnums_pb2.PortNum.POSITION_APP: + if portnum == portnums_pb2.PortNum.POSITION_APP: topic = "meshtastic.receive.position" pb = mesh_pb2.Position() pb.ParseFromString(meshPacket.decoded.data.payload) @@ -497,7 +501,7 @@ class MeshInterface: self._getOrCreateByNum(asDict["from"])["position"] = p # decode user protobufs and update nodedb, provide decoded version as "position" in the published msg - if asDict["decoded"]["data"]["portnum"] == portnums_pb2.PortNum.NODEINFO_APP: + if portnum == portnums_pb2.PortNum.NODEINFO_APP: topic = "meshtastic.receive.user" pb = mesh_pb2.User() pb.ParseFromString(meshPacket.decoded.data.payload)