-
Notifications
You must be signed in to change notification settings - Fork 1k
[aioble] After timeout, reconnection is successful. (Peripherals are always powered off) #950
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
Comments
I am facing a similar issue which appears to be related. I have a crappy device that after it disconnects it continues to send trailing connectable advertisements but when a connection attempt is made, the device simply does not respond. Its advertisements also cease. Eventually the connection attempt times out, but the system remains 'connected' in some sense and the system is corrupted. If I take a measurement with another device that is known (a bonded reconnect) I get EINVAL 22 errors all over the place. If, instead, I try and connect to the original device that had the trailing advertisements I get a connection event in the aioble event handler but nothing further happens. The only recovery is to reboot that application. |
I think I have found the reason for the issue and the solution. When the connection attempt times out, aioble fails to cancel the ongoing connection. If you then make tour device discoverable again, the connection will complete (the IRQ gets handled) but there is no longer any support for it so it goes nowhere. If you try to connect with another device, when aioble calls the I was able to solve the issue by calling
I am assuming this timeout get signaled ONLY when the connection attempt times out. |
|
I would like to be able to call the cancel connect on the timeout of the connect attempt, but it was not clear how to do that. I could not find a way to identify the cause of the timeout so I handled it in the timeout. So far it solves the problem I have and has not introduced a problem. How would I do this? I could not see how to do it in this block of code with self._connection().timeout(timeout_ms): which is where I would really like to do it. |
Sorry for the poor explanation. (I use a translator.) Call ble.gap_connect(None) in the exception handler as follows.
In the following, the DeviceTimeout class is used to show where ‘read’ starts the timeout.
In the code below, gap_connect(None) is called on a 'read' timeout.
|
I statically analyzed the code and found the same issue. There's a missing gap_connect(None) after timeouts. I can make a PR? |
Yes, please create a PR. |
The company I worked for folded so I am not doing this anymore and have gone back to meteorological research vs Bluetooth health devices. I will say that the fix I used has worked and has not caused any unwanted side effects in operation. Some other issues you might want to look at in this PR is better handling of disconnects from the remote peer. There needs to be a more direct connection between aioble and the application to assure that the application does not try to do something as if connected when in fact it is disconnected. As it is know, by the time the application gets signaled of the disconnect the application can try and do something that it should not do in the disconnected state. That will cause catastrophic failures in aioble. I had to create an application 'global' that was set in aioble in the disconnect callback. The application would use this variable to check the connection state instead of the aioble APIs. The other big ticket item is pairing/bonding support. It does not exist for the PICO-W. We had to do a lot of low level work to support bonding and bonded reconnects using the BlueKitchen btStack. We could not operate with many medical health devices without it. In this task one needs to consider
which are handled differently in the btStack (unfortunately). The btStack handles the security requests internally (but the application does not know it so you have to add code to tell the application that pairing/encryption has happened). The btStack does not handle the insufficient authentication error and that needs to be passed up to the application so it can invoke pairing/encryption
|
The other device is powered off. However, after a connection timeout, it appears to be connected when retried. In fact, it is failing.
I'm not a native speaker, so sorry if my writing is wrong.
Environment
Steps to reproduce
Code used for testing
I added exception handling because of the following problem. (It is not a good idea to fix it in this place.)
The text was updated successfully, but these errors were encountered: