Add in a retry mechanism for channel settings

Attempts multiple times to fetch things over the admin channel
before giving up.
This commit is contained in:
Derek Arnold
2024-09-03 21:47:07 -05:00
parent b4bd9568e4
commit 9612aea9b9
3 changed files with 29 additions and 8 deletions

View File

@@ -1423,6 +1423,12 @@ def initParser():
action="append",
)
group.add_argument(
"--channel-fetch-retries",
help=("Attempt to retrieve channel settings for --ch-set this many times before giving up."),
default=3,
)
group.add_argument(
"--ch-vlongslow",
help="Change to the very long-range and slow channel",

View File

@@ -314,7 +314,7 @@ class MeshInterface: # pylint: disable=R0902
return table
def getNode(
self, nodeId: str, requestChannels: bool = True
self, nodeId: str, requestChannels: bool = True, requestChannelRetries: int = 3
) -> meshtastic.node.Node:
"""Return a node object which contains device settings and channel info"""
if nodeId in (LOCAL_ADDR, BROADCAST_ADDR):
@@ -325,8 +325,22 @@ class MeshInterface: # pylint: disable=R0902
if requestChannels:
logging.debug("About to requestChannels")
n.requestChannels()
if not n.waitForConfig():
our_exit("Error: Timed out waiting for channels")
retries_left = requestChannelRetries
last_index: int = 0
while retries_left > 0:
retries_left -= 1
if not n.waitForConfig():
new_index: int = len(n.partialChannels)
# each time we get a new channel, reset the counter
if new_index != last_index:
retries_left = requestChannelRetries - 1
if retries_left <= 0:
our_exit(f"Error: Timed out waiting for channels, giving up")
print("Timed out trying to retrieve channel info, retrying")
n.requestChannels(startingIndex=len(n.partialChannels))
last_index = new_index
else:
break
return n
def sendText(

View File

@@ -77,13 +77,14 @@ class Node:
self.channels = channels
self._fixupChannels()
def requestChannels(self):
def requestChannels(self, startingIndex: int = 0):
"""Send regular MeshPackets to ask channels."""
logging.debug(f"requestChannels for nodeNum:{self.nodeNum}")
self.channels = None
self.partialChannels = [] # We keep our channels in a temp array until finished
self._requestChannel(0)
# only initialize if we're starting out fresh
if startingIndex == 0:
self.channels = None
self.partialChannels = [] # We keep our channels in a temp array until finished
self._requestChannel(startingIndex)
def onResponseRequestSettings(self, p):
"""Handle the response packets for requesting settings _requestSettings()"""