From 4cc283d0041a75c6958603efa896e57f31b94ac4 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 24 Aug 2024 17:27:42 -0500 Subject: [PATCH] Add the admin sessionkey_only request --- meshtastic/__main__.py | 8 ++++++-- meshtastic/node.py | 29 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index e7886e6..0722c34 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -39,7 +39,7 @@ except ImportError as e: have_powermon = False powermon_exception = e meter = None -from meshtastic.protobuf import channel_pb2, config_pb2, portnums_pb2 +from meshtastic.protobuf import admin_pb2, channel_pb2, config_pb2, portnums_pb2 from meshtastic.version import get_active_version def onReceive(packet, interface): @@ -334,7 +334,11 @@ def onConnected(interface): closeNow = True waitForAckNak = True print(f"Setting device owner to {args.set_owner}") - interface.getNode(args.dest, False).setOwner(args.set_owner) + node = interface.getNode(args.dest, False) + node.requestConfig( + admin_pb2.AdminMessage.SESSIONKEY_CONFIG + ) + node.setOwner(args.set_owner) if args.set_owner_short: closeNow = True diff --git a/meshtastic/node.py b/meshtastic/node.py index d6e2432..cb5f29b 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -88,6 +88,7 @@ class Node: def onResponseRequestSettings(self, p): """Handle the response packets for requesting settings _requestSettings()""" logging.debug(f"onResponseRequestSetting() p:{p}") + config_values = None if "routing" in p["decoded"]: if p["decoded"]["routing"]["errorReason"] != "NONE": print(f'Error on response: {p["decoded"]["routing"]["errorReason"]}') @@ -102,7 +103,8 @@ class Node: config_type = self.localConfig.DESCRIPTOR.fields_by_name.get( camel_to_snake(field) ) - config_values = getattr(self.localConfig, config_type.name) + if config_type is not None: + config_values = getattr(self.localConfig, config_type.name) elif "getModuleConfigResponse" in adminMessage: resp = adminMessage["getModuleConfigResponse"] field = list(resp.keys())[0] @@ -115,9 +117,10 @@ class Node: "Did not receive a valid response. Make sure to have a shared channel named 'admin'." ) return - for key, value in resp[field].items(): - setattr(config_values, camel_to_snake(key), value) - print(f"{str(camel_to_snake(field))}:\n{str(config_values)}") + if config_values is not None: + for key, value in resp[field].items(): + setattr(config_values, camel_to_snake(key), value) + print(f"{str(camel_to_snake(field))}:\n{str(config_values)}") def requestConfig(self, configType): """Request the config from the node via admin message""" @@ -126,16 +129,18 @@ class Node: else: onResponse = self.onResponseRequestSettings print("Requesting current config from remote node (this can take a while).") + p = admin_pb2.AdminMessage() + if isinstance(configType, int): + p.get_config_request = configType - msgIndex = configType.index - if configType.containing_type.name == "LocalConfig": - p = admin_pb2.AdminMessage() - p.get_config_request = msgIndex - self._sendAdmin(p, wantResponse=True, onResponse=onResponse) else: - p = admin_pb2.AdminMessage() - p.get_module_config_request = msgIndex - self._sendAdmin(p, wantResponse=True, onResponse=onResponse) + msgIndex = configType.index + if configType.containing_type.name == "LocalConfig": + p.get_config_request = msgIndex + else: + p.get_module_config_request = msgIndex + + self._sendAdmin(p, wantResponse=True, onResponse=onResponse) if onResponse: self.iface.waitForAckNak()