getsenic / gatt-python

Bluetooth GATT SDK for Python
MIT License
318 stars 86 forks source link

Try reconnecting once when NoReply error was thrown when calling .connect() #3

Open larsblumberg opened 7 years ago

AndreV2890 commented 3 years ago

Hi all

I resume this issue because I have some trouble with reconnections. In my case, I have a server device that automatically turns off if it is not used for a while. Once it turns off, on the client-side my python script attempts reconnection. If the server device turns on within 1-2 minutes everything works but if the server turns after a long period the reconnection seems to fail. On the client-side, I receive a NoReply error, and then a new reconnection is attempted but this last reconnection is stuck in an infinite wait.

`def init(self, manager, mac_address, auto_reconnect=True): super().init(manager=manager, mac_address=mac_address) self.auto_reconnect = auto_reconnect

def connect(self):
    print("Connecting...")
    super().connect()

def connect_succeeded(self):
    super().connect_succeeded()
    print("[%s] Connected" % (self.mac_address))

def connect_failed(self, error):
    super().connect_failed(error)
    print("[%s] Connection failed: %s" % (self.mac_address, str(error)))

    if self.auto_reconnect:
        self.connect()

def disconnect_succeeded(self):
    super().disconnect_succeeded()
    print("[%s] Disconnected" % (self.mac_address))

    if self.auto_reconnect:
        self.connect()`

So, are there any tips, recommendations?