I am trying to write a script that will connect to many drones throughout its execution. I have noticed that the drones are inconsistent with their ports and can often cause timeout errors. Currently this is the script I wrote:
from dronekit import connect, TimeoutError
connection_strings = ['', '', '']
vehicles = []
start = 'tcp:127.0.0.1:57'
temp = 6
for connection in connection_strings:
connection = start + str(temp) + '2'
print('Trying ' + connection)
try:
vehicles.append(connect(connection, wait_ready=True))
except TimeoutError as err:
connection = start + str(temp) + '3'
vehicles.append(connect(connection, wait_ready=True))
print('Connected to ': ' + connection)
temp+=1
The problem I am encountering is that this just becomes an infinite connection stream for the first connection and never actually results in receiving a heartbeat from any drone. Am I doing the error handling correctly?