Skip to content

Commit 32682b5

Browse files
authored
Merge pull request #589 from ianmcorvidae/nodeless-startup
Allow a faster nodedb-less startup on 2.3.11+ with `--no-nodes`
2 parents ee857c5 + 9dab76b commit 32682b5

7 files changed

Lines changed: 31 additions & 15 deletions

File tree

meshtastic/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect
117117
format is Mmmss (where M is 1+the numeric major number. i.e. 20120 means 1.1.20
118118
"""
119119

120+
NODELESS_WANT_CONFIG_ID = 69420
121+
"""A special thing to pass for want_config_id that instructs nodes to skip sending nodeinfos other than its own."""
122+
120123
publishingThread = DeferredExecution("publishing")
121124

122125

meshtastic/__main__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,11 @@ def common():
10501050
meshtastic.util.our_exit("BLE scan finished", 0)
10511051
return
10521052
elif args.ble:
1053-
client = BLEInterface(args.ble, debugOut=logfile, noProto=args.noproto)
1053+
client = BLEInterface(args.ble, debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes)
10541054
elif args.host:
10551055
try:
10561056
client = meshtastic.tcp_interface.TCPInterface(
1057-
args.host, debugOut=logfile, noProto=args.noproto
1057+
args.host, debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes
10581058
)
10591059
except Exception as ex:
10601060
meshtastic.util.our_exit(
@@ -1063,7 +1063,7 @@ def common():
10631063
else:
10641064
try:
10651065
client = meshtastic.serial_interface.SerialInterface(
1066-
args.port, debugOut=logfile, noProto=args.noproto
1066+
args.port, debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes
10671067
)
10681068
except PermissionError as ex:
10691069
username = os.getlogin()
@@ -1078,7 +1078,7 @@ def common():
10781078
if client.devPath is None:
10791079
try:
10801080
client = meshtastic.tcp_interface.TCPInterface(
1081-
"localhost", debugOut=logfile, noProto=args.noproto
1081+
"localhost", debugOut=logfile, noProto=args.noproto, noNodes=args.no_nodes
10821082
)
10831083
except Exception as ex:
10841084
meshtastic.util.our_exit(
@@ -1453,6 +1453,13 @@ def initParser():
14531453
action="store_true",
14541454
)
14551455

1456+
group.add_argument(
1457+
"--no-nodes",
1458+
help="Request that the node not send node info to the client. "
1459+
"Will break things that depend on the nodedb, but will speed up startup. Requires 2.3.11+ firmware.",
1460+
action="store_true",
1461+
)
1462+
14561463
group.add_argument(
14571464
"--setalt",
14581465
help="Set device altitude in meters (allows use without GPS), and enable fixed position.",

meshtastic/ble_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BLEState(): # pylint: disable=C0115
3232
MESH = False
3333

3434

35-
def __init__(self, address: Optional[str], noProto: bool = False, debugOut = None):
35+
def __init__(self, address: Optional[str], noProto: bool = False, debugOut = None, noNodes: bool = False):
3636
self.state = BLEInterface.BLEState()
3737

3838
if not address:
@@ -60,7 +60,7 @@ def __init__(self, address: Optional[str], noProto: bool = False, debugOut = Non
6060
return
6161

6262
logging.debug("Mesh init starting")
63-
MeshInterface.__init__(self, debugOut = debugOut, noProto = noProto)
63+
MeshInterface.__init__(self, debugOut = debugOut, noProto = noProto, noNodes = noNodes)
6464
self._startConfig()
6565
if not self.noProto:
6666
self._waitConnected(timeout = 60.0)

meshtastic/mesh_interface.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
BROADCAST_ADDR,
2727
BROADCAST_NUM,
2828
LOCAL_ADDR,
29+
NODELESS_WANT_CONFIG_ID,
2930
ResponseHandler,
3031
protocols,
3132
publishingThread,
@@ -41,7 +42,7 @@
4142
)
4243

4344

44-
class MeshInterface:
45+
class MeshInterface: # pylint: disable=R0902
4546
"""Interface class for meshtastic devices
4647
4748
Properties:
@@ -57,12 +58,14 @@ def __init__(self, message):
5758
self.message = message
5859
super().__init__(self.message)
5960

60-
def __init__(self, debugOut=None, noProto: bool=False) -> None:
61+
def __init__(self, debugOut=None, noProto: bool=False, noNodes: bool=False) -> None:
6162
"""Constructor
6263
6364
Keyword Arguments:
6465
noProto -- If True, don't try to run our protocol on the
6566
link - just be a dumb serial client.
67+
noNodes -- If True, instruct the node to not send its nodedb
68+
on startup, just other configuration information.
6669
"""
6770
self.debugOut = debugOut
6871
self.nodes: Optional[Dict[str,Dict]] = None # FIXME
@@ -81,7 +84,8 @@ def __init__(self, debugOut=None, noProto: bool=False) -> None:
8184
random.seed() # FIXME, we should not clobber the random seedval here, instead tell user they must call it
8285
self.currentPacketId: int = random.randint(0, 0xFFFFFFFF)
8386
self.nodesByNum: Optional[Dict[int, Dict]] = None
84-
self.configId: Optional[int] = None
87+
self.noNodes: bool = noNodes
88+
self.configId: Optional[int] = NODELESS_WANT_CONFIG_ID if noNodes else None
8589
self.gotResponse: bool = False # used in gpio read
8690
self.mask: Optional[int] = None # used in gpio read and gpio watch
8791
self.queueStatus: Optional[mesh_pb2.QueueStatus] = None
@@ -713,7 +717,8 @@ def _startConfig(self):
713717
self._localChannels = [] # empty until we start getting channels pushed from the device (during config)
714718

715719
startConfig = mesh_pb2.ToRadio()
716-
self.configId = random.randint(0, 0xFFFFFFFF)
720+
if self.configId is None or not self.noNodes:
721+
self.configId = random.randint(0, 0xFFFFFFFF)
717722
startConfig.want_config_id = self.configId
718723
self._sendToRadio(startConfig)
719724

meshtastic/serial_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class SerialInterface(StreamInterface):
1919
"""Interface class for meshtastic devices over a serial link"""
2020

21-
def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto=False, connectNow=True):
21+
def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto=False, connectNow=True, noNodes: bool=False):
2222
"""Constructor, opens a connection to a specified serial port, or if unspecified try to
2323
find one Meshtastic device by probing
2424
@@ -62,7 +62,7 @@ def __init__(self, devPath: Optional[str]=None, debugOut=None, noProto=False, co
6262
time.sleep(0.1)
6363

6464
StreamInterface.__init__(
65-
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow
65+
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes
6666
)
6767

6868
def close(self):

meshtastic/stream_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class StreamInterface(MeshInterface):
2020
"""Interface class for meshtastic devices over a stream link (serial, TCP, etc)"""
2121

22-
def __init__(self, debugOut=None, noProto=False, connectNow=True):
22+
def __init__(self, debugOut=None, noProto=False, connectNow=True, noNodes=False):
2323
"""Constructor, opens a connection to self.stream
2424
2525
Keyword Arguments:
@@ -43,7 +43,7 @@ def __init__(self, debugOut=None, noProto=False, connectNow=True):
4343
# FIXME, figure out why daemon=True causes reader thread to exit too early
4444
self._rxThread = threading.Thread(target=self.__reader, args=(), daemon=True)
4545

46-
MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto)
46+
MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto, noNodes=noNodes)
4747

4848
# Start the reader thread after superclass constructor completes init
4949
if connectNow:

meshtastic/tcp_interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(
1717
noProto=False,
1818
connectNow=True,
1919
portNumber=4403,
20+
noNodes:bool=False,
2021
):
2122
"""Constructor, opens a connection to a specified IP address/hostname
2223
@@ -38,7 +39,7 @@ def __init__(
3839
self.socket = None
3940

4041
StreamInterface.__init__(
41-
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow
42+
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes
4243
)
4344

4445
def _socket_shutdown(self):

0 commit comments

Comments
 (0)