diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index fd9f36b..ce26069 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -292,6 +292,14 @@ def onConnected(interface): if args.device_metadata: closeNow = True interface.getNode(args.dest).getMetadata() + + if args.begin_edit: + closeNow = True + interface.getNode(args.dest, False).beginSettingsTransaction() + + if args.commit_edit: + closeNow = True + interface.getNode(args.dest, False).commitSettingsTransaction() if args.factory_reset: closeNow = True @@ -386,6 +394,8 @@ def onConnected(interface): configuration = yaml.safe_load(file) closeNow = True + interface.getNode(args.dest, False).beginSettingsTransaction() + if 'owner' in configuration: print(f"Setting device owner to {configuration['owner']}") waitForAckNak = True @@ -444,7 +454,8 @@ def onConnected(interface): for pref in configuration['module_config'][section]: setPref(moduleConfig, f"{section}.{pref}", str(configuration['module_config'][section][pref])) interface.getNode(args.dest).writeConfig(section) - + + interface.getNode(args.dest, False).commitSettingsTransaction() print("Writing modified configuration to device") if args.export_config: diff --git a/meshtastic/node.py b/meshtastic/node.py index a27c3e6..91e3062 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -481,6 +481,32 @@ class Node: else: onResponse = self.onAckNak return self._sendAdmin(p, onResponse=onResponse) + + def beginSettingsTransaction(self): + """Tell the node to open a transaction to edit settings.""" + p = admin_pb2.AdminMessage() + p.begin_edit_settings = True + logging.info(f"Telling open a transaction to edit settings") + + # If sending to a remote node, wait for ACK/NAK + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + + def commitSettingsTransaction(self): + """Tell the node to commit the open transaction for editing settings.""" + p = admin_pb2.AdminMessage() + p.commit_edit_settings = True + logging.info(f"Telling node to commit open transaction for editing settings") + + # If sending to a remote node, wait for ACK/NAK + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) def rebootOTA(self, secs: int = 10): """Tell the node to reboot into factory firmware."""