mirror of
https://github.com/meshtastic/python.git
synced 2026-04-18 13:57:00 -04:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user