Skip to content

Commit b280d0b

Browse files
authored
Merge pull request #541 from ianmcorvidae/removenode
Add --remove-node (fixes #514)
2 parents 9f2b54e + 439b1ad commit b280d0b

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

meshtastic/__main__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ def onConnected(interface):
365365
waitForAckNak = True
366366
interface.getNode(args.dest, False).factoryReset()
367367

368+
if args.remove_node:
369+
closeNow = True
370+
waitForAckNak = True
371+
interface.getNode(args.dest, False).removeNode(args.remove_node)
372+
368373
if args.reset_nodedb:
369374
closeNow = True
370375
waitForAckNak = True
@@ -1332,9 +1337,13 @@ def initParser():
13321337
action="store_true",
13331338
)
13341339

1340+
group.add_argument(
1341+
"--remove-node",
1342+
help="Tell the destination node to remove a specific node from its DB, by node number or ID"
1343+
)
13351344
group.add_argument(
13361345
"--reset-nodedb",
1337-
help="Tell the destination node clear its list of nodes",
1346+
help="Tell the destination node to clear its list of nodes",
13381347
action="store_true",
13391348
)
13401349

meshtastic/node.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import logging
66
import time
77

8+
from typing import Union
9+
810
from meshtastic import admin_pb2, apponly_pb2, channel_pb2, localonly_pb2, portnums_pb2
911
from meshtastic.util import (
1012
Timeout,
@@ -603,6 +605,23 @@ def factoryReset(self):
603605
onResponse = self.onAckNak
604606
return self._sendAdmin(p, onResponse=onResponse)
605607

608+
def removeNode(self, nodeId: Union[int, str]):
609+
"""Tell the node to remove a specific node by ID"""
610+
if isinstance(nodeId, str):
611+
if nodeId.startswith("!"):
612+
nodeId = int(nodeId[1:], 16)
613+
else:
614+
nodeId = int(nodeId)
615+
616+
p = admin_pb2.AdminMessage()
617+
p.remove_by_nodenum = nodeId
618+
619+
if self == self.iface.localNode:
620+
onResponse = None
621+
else:
622+
onResponse = self.onAckNak
623+
return self._sendAdmin(p, onResponse=onResponse)
624+
606625
def resetNodeDb(self):
607626
"""Tell the node to reset its list of nodes."""
608627
p = admin_pb2.AdminMessage()

0 commit comments

Comments
 (0)