-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix get_services()
fails because no GattSession
#973
Conversation
Since the following error occurred when connecting, set the MTU to the default 20 to avoid it. `AttributeError: 'NoneType' object has no attribute 'max_pdu_size'`
If |
@dlech Thank you for your reply! Test code is here: https://github.com/nv-h/nRF52_sensors/blob/master/test/search_and_connect.py
|
Thanks for the logs.
This is what I was expecting to see. It looks as if the device is disconnecting even though we tell Windows to stay connected. Can you also get a Wireshark log of the Bluetooth packets when the problem happens (see troubleshooting page in bleak docs for howto)? I would like to see if Windows is disconnecting or if the device itself is disconnecting or if it is not disconnecting at all. |
I see. So, does my workaround match? I've attached the packet capture results when I try and reproduce it 3 times. |
Does this mean the first two attempts did not have a problem and the 3rd attempt did have the problem? |
Yes! |
This shows that the device disconnected itself about 1/4 of a second after connecting (before the MTU exchange was complete). So, I don't think the workaround is the correct solution here. Instead, the connect method should fail because the device disconnected before the services could be retrieved. Then the connection can be retried later. |
Thank you for the explanation. So, I think that try to write the retry process in the application code by catch AttributeError. |
I would accept a PR that adds if not self.is_connected:
raise BleakError("Not connected") to That would be more informative than an AttributeError. |
Thank you. I added it like this commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Can you also add a changelog entry?
Thank you for review. I changed place and added changelog. |
Based on BlueZ's implementation
Added a connection check referring to BlueZ's implementation. I didn't see the implementation, so I'm sorry for bothering you twice. |
Merged, thanks! |
Since the following error occurred when connecting, set the MTU to the default 20 to avoid it.
AttributeError: 'NoneType' object has no attribute 'max_pdu_size'
Tested by Python 3.9 on Windows 11.