From 439b1ade2ebd2057e35e6725fb78ffa6e9d77c9f Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Mon, 8 Apr 2024 14:58:15 -0700 Subject: [PATCH] Add --remove-node (fixes #514) --- meshtastic/__main__.py | 11 ++++++++++- meshtastic/node.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 9502f711..3c0b20b9 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -365,6 +365,11 @@ def onConnected(interface): waitForAckNak = True interface.getNode(args.dest, False).factoryReset() + if args.remove_node: + closeNow = True + waitForAckNak = True + interface.getNode(args.dest, False).removeNode(args.remove_node) + if args.reset_nodedb: closeNow = True waitForAckNak = True @@ -1332,9 +1337,13 @@ def initParser(): action="store_true", ) + group.add_argument( + "--remove-node", + help="Tell the destination node to remove a specific node from its DB, by node number or ID" + ) group.add_argument( "--reset-nodedb", - help="Tell the destination node clear its list of nodes", + help="Tell the destination node to clear its list of nodes", action="store_true", ) diff --git a/meshtastic/node.py b/meshtastic/node.py index cc42cc4d..1fc1b379 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -5,6 +5,8 @@ import logging import time +from typing import Union + from meshtastic import admin_pb2, apponly_pb2, channel_pb2, localonly_pb2, portnums_pb2 from meshtastic.util import ( Timeout, @@ -603,6 +605,23 @@ def factoryReset(self): onResponse = self.onAckNak return self._sendAdmin(p, onResponse=onResponse) + def removeNode(self, nodeId: Union[int, str]): + """Tell the node to remove a specific node by ID""" + if isinstance(nodeId, str): + if nodeId.startswith("!"): + nodeId = int(nodeId[1:], 16) + else: + nodeId = int(nodeId) + + p = admin_pb2.AdminMessage() + p.remove_by_nodenum = nodeId + + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + def resetNodeDb(self): """Tell the node to reset its list of nodes.""" p = admin_pb2.AdminMessage()