Page 1 of 1

Code for automatic reconnect

Posted: Fri Aug 27, 2021 2:59 pm
by huizerd
Hi all,

I'm working with the basic asynchronous logging example (https://github.com/bitcraze/crazyflie-l ... asiclog.py) and trying to 1) keep trying to make an initial connection until it finds a Crazyflie, and 2) keep trying to reconnect if the logger has lost connection to a previously connected Crazyflie. I got 1) to work by just adding a while loop in the __init__ of the logger and closing and opening the link until it connects, but I'm not sure how to achieve 2). Is there any chance somebody of you has worked on this before? Thanks!

Jesse

Re: Code for automatic reconnect

Posted: Mon Aug 30, 2021 4:17 am
by jonasdn
Hi Jesse!

You could try to work with the callbacks that are there! Everytime you disconnect from a Crazyflie the function ...

Code: Select all

def _disconnected(self, link_uri):
        """Callback when the Crazyflie is disconnected (called in all cases)"""
        print('Disconnected from %s' % link_uri)
        self.is_connected = False
... will be called so you can take action to reconnect.

Re: Code for automatic reconnect

Posted: Tue Aug 31, 2021 11:51 am
by huizerd
Hi Jonas,

Thanks! Using the callbacks gave me recursive reconnection attempts, but creating a separate reconnect function that is called in an outside loop worked for me.