getsenic / gatt-python

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

Charactristic notify callback not removed on device disconnect #63

Open ashesman opened 3 years ago

ashesman commented 3 years ago

It seems that the characteristic notify callback that is registered with the underlying layer is not removed when a device disconnects. When you reconnect to that device and register a notify callback it is called twice for each time data is received. Every time you disconnect/reconnect and register the callback you get one more call of the callback each time. Note that a new derived gatt.Device is instantiated on each connect.

In my disconnect code I call .enable_notifications(False) on the particular characteristic in question. Seems to work correctly if the central is causing the disconnect. However, if the peripheral device is remotely disconnected (e.g. powered off), then device.services is no longer valid to obtain the characteristic to call enable_notifications on.

I would assume it is the responsibility of the destructing code to clean up any callbacks registered?

Any ideas how to work around this?