diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index f4d91fd..6ffc3d7 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -199,6 +199,13 @@ def _receiveInfoUpdate(iface, asDict): iface._getOrCreateByNum(asDict["from"])["snr"] = asDict.get("rxSnr") iface._getOrCreateByNum(asDict["from"])["hopLimit"] = asDict.get("hopLimit") +def _onAdminReceive(iface, asDict): + """Special auto parsing for received messages""" + logging.debug(f"in _onAdminReceive() asDict:{asDict}") + if "decoded" in asDict: + if "admin" in asDict["decoded"] and "from" in asDict: + adminMessage: admin_pb2.AdminMessage = asDict["decoded"]["admin"] + iface._getOrCreateByNum(asDict["from"])["adminSessionPassKey"] = adminMessage["raw"].session_passkey """Well known message payloads can register decoders for automatic protobuf parsing""" protocols = { @@ -238,4 +245,7 @@ protocols = { portnums_pb2.PortNum.STORE_FORWARD_APP: KnownProtocol("storeforward", storeforward_pb2.StoreAndForward), portnums_pb2.PortNum.NEIGHBORINFO_APP: KnownProtocol("neighborinfo", mesh_pb2.NeighborInfo), portnums_pb2.PortNum.MAP_REPORT_APP: KnownProtocol("mapreport", mqtt_pb2.MapReport), + portnums_pb2.PortNum.ADMIN_APP: KnownProtocol( + "admin", admin_pb2.AdminMessage, _onAdminReceive + ), } diff --git a/meshtastic/node.py b/meshtastic/node.py index 1a34ea0..da1f517 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -95,7 +95,7 @@ class Node: else: self.iface._acknowledgment.receivedAck = True print("") - adminMessage = p["decoded"]["admin"] + adminMessage: admin_pb2.AdminMessage = p["decoded"]["admin"] if "getConfigResponse" in adminMessage: resp = adminMessage["getConfigResponse"] field = list(resp.keys())[0] @@ -833,7 +833,12 @@ class Node: ): # unless a special channel index was used, we want to use the admin index adminIndex = self.iface.localNode._getAdminChannelIndex() logging.debug(f"adminIndex:{adminIndex}") - + if isinstance(self.nodeNum, int): + nodeid = self.nodeNum + elif self.nodeNum.startswith("!"): + nodeid = int(self.nodeNum[1:],16) + if ("adminSessionPassKey" in self.iface._getOrCreateByNum(nodeid)): + p.session_passkey = self.iface._getOrCreateByNum(nodeid).get("adminSessionPassKey") return self.iface.sendData( p, self.nodeNum,