From 3811226a61815fdb3576d64d9c1ae7433e0151c5 Mon Sep 17 00:00:00 2001 From: Derek Arnold Date: Tue, 3 Sep 2024 22:12:03 -0500 Subject: [PATCH] add a configurable timeout --- meshtastic/__main__.py | 9 ++++++++- meshtastic/mesh_interface.py | 4 ++-- meshtastic/node.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index b43d595..fcfb385 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -275,7 +275,8 @@ def onConnected(interface): # convenient place to store any keyword args we pass to getNode getNode_kwargs = { - "requestChannelRetries": int(args.channel_fetch_retries) + "requestChannelRetries": int(args.channel_fetch_retries), + "timeout": int(args.timeout) } # do not print this line if we are exporting the config @@ -1434,6 +1435,12 @@ def initParser(): default=3, ) + group.add_argument( + "--timeout", + help="How long to wait for replies", + default=300 + ) + group.add_argument( "--ch-vlongslow", help="Change to the very long-range and slow channel", diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index b289668..48fff56 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -314,13 +314,13 @@ class MeshInterface: # pylint: disable=R0902 return table def getNode( - self, nodeId: str, requestChannels: bool = True, requestChannelRetries: int = 3 + self, nodeId: str, requestChannels: bool = True, requestChannelRetries: int = 3, timeout: int = 300 ) -> meshtastic.node.Node: """Return a node object which contains device settings and channel info""" if nodeId in (LOCAL_ADDR, BROADCAST_ADDR): return self.localNode else: - n = meshtastic.node.Node(self, nodeId) + n = meshtastic.node.Node(self, nodeId, timeout=timeout) # Only request device settings and channel info when necessary if requestChannels: logging.debug("About to requestChannels") diff --git a/meshtastic/node.py b/meshtastic/node.py index 91c2d41..964e680 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -25,14 +25,14 @@ class Node: Includes methods for localConfig, moduleConfig and channels """ - def __init__(self, iface, nodeNum, noProto=False): + def __init__(self, iface, nodeNum, noProto=False, timeout: int = 300): """Constructor""" self.iface = iface self.nodeNum = nodeNum self.localConfig = localonly_pb2.LocalConfig() self.moduleConfig = localonly_pb2.LocalModuleConfig() self.channels = None - self._timeout = Timeout(maxSecs=300) + self._timeout = Timeout(maxSecs=timeout) self.partialChannels = None self.noProto = noProto self.cannedPluginMessage = None