Closed Owenber123 closed 3 years ago
Looking at the Bluezero code for adding a characteristic callback:
https://github.com/ukBaz/python-bluezero/blob/main/bluezero/GATT.py#L250-L251
self.characteristic_props.connect_to_signal('PropertiesChanged',
callback)
There doesn't appear to be anything that removes a callback from a characteristic so when you add a callback a second time it connects another one to the PropertiesChanged signal. I would expect that if you keep adding callbacks the number notifications would go up.
The quick fix for this is that your code could not add a callback every time it calls startListenImageTX
. When it is doing a restart, it only does a start_notify()
I'll also investigate if there is a better way of checking if a duplicate callback is being added.
I've created a new branch with an experiment. The commit is at:
https://github.com/ukBaz/python-bluezero/commit/6028928567343aecdc2e0fa4d4de761335891380
When calling add_characteristic_cb
with None
or no value then it will remove the callback from the signal. My quick experiment seemed to work but would be interested in feedback from you on using it in your situation.
Also, open to any feedback if this is the best way of doing it.
@owenber123 Did you get chance to look at this to see if it worked for you?
Hello,
I am having an issue with notifications when I attempt to stop_notify and then start_notify again. It seems like the second time around I am receiving the data that I received the first time in my new callback function. I have validated that my device is not sending the data twice the second time. Here is my flow of execution:
main:
device:
Here are the first 100 bytes of data for both transmissions to prove its an overlap and not one after the other, seems to be every 32 bytes, I'm assuming that's just how changed_props is constructed:
I am convinced that the char.stop_notify() handles the clean up required to re enable notifications during the same connection and I have tried almost everything to prove that Python is not reusing the same image collection helper instance. It seems like the data is being send through the callback twice or there are two callbacks linked to the characteristic. Any ideas on my wrongdoing or additional debug advice would be greatly appreciated. Thanks in advance.