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

@@ -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(