From 4bf61d4c9803f0f44e6a44c462fd7bb61177e3ba Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 3 Mar 2025 06:48:06 -0600 Subject: [PATCH] Add backup / restore admin commands --- meshtastic/__main__.py | 15 +++++++++++++++ meshtastic/node.py | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index e5a9243..7528e2a 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -462,6 +462,21 @@ def onConnected(interface): waitForAckNak = True interface.getNode(args.dest, False, **getNode_kwargs).removeFavorite(args.remove_favorite_node) + if args.backup_prefs: + closeNow = True + waitForAckNak = True + interface.getNode(args.dest, False, **getNode_kwargs).re(args.backup_preferences) + + if args.restore_prefs: + closeNow = True + waitForAckNak = True + interface.getNode(args.dest, False, **getNode_kwargs).re(args.backup_preferences) + + if args.remove_backup_prefs: + closeNow = True + waitForAckNak = True + interface.getNode(args.dest, False, **getNode_kwargs).re(args.remove_backup_preferences) + if args.set_ignored_node: closeNow = True waitForAckNak = True diff --git a/meshtastic/node.py b/meshtastic/node.py index f8e81f6..98fbdcc 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -707,8 +707,47 @@ class Node: onResponse = self.onAckNak return self._sendAdmin(p, onResponse=onResponse) + def backupPreferences(self, location: int = 0): + """Tell the node to backup preferences to flash.""" + self.ensureSessionKey() + + p = admin_pb2.AdminMessage() + p.backup_preferences = location + + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + + def restorePreferences(self, location: int = 0): + """Tell the node to restore preferences from backup.""" + self.ensureSessionKey() + + p = admin_pb2.AdminMessage() + p.restore_preferences = location + + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + + def removePreferencesBackups(self, location: int = 0): + """Tell the node to remove backup preferences from the filesystem.""" + self.ensureSessionKey() + + p = admin_pb2.AdminMessage() + p.remove_backup_preferences = location + + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + def removeFavorite(self, nodeId: Union[int, str]): - """Tell the node to set the specified node ID to be un-favorited on the NodeDB on the device""" + """Tell the node to set the specified node ID to be un-favorited on the NodeDB on the device.""" self.ensureSessionKey() if isinstance(nodeId, str): if nodeId.startswith("!"):