aioble aysnc await not allowing capture of unsolicited events #13769
Replies: 2 comments 5 replies
-
In which context do you want to use the |
Beta Was this translation helpful? Give feedback.
-
Okay, I know what a pull request is, but the work done to solve this problem is not complete enough to be added to this project. In addition, there are issues that are being worked around which should not be the case in the final distribution. I suppose the biggest case in point is that sometimes the btstack handles the pairing and encryption and aioble and the application (my code) knows nothing about it. This happens when the device issues a security request. If the device does not issue security requests, my code has to initiate pairing via aioble. The correct solution would do one or the other - the btstack handles all pairing/bonding/encryption on reconnect needs, or the application does. I would prefer the latter! RIght now I handle the security request by making a task that registers for the encryption changed event in aioble which is started at connection. To do that I had to add another method to aioble does exactly what the pairing method does except call pair! When the pairing invoked by the btstack is done, aioble gets signaled which signlas my app. Both aioble and my app now know that pairing/bonding/encryption occurred. However, if my app needs to initiate pairing (needed when the device does not do security requests) I have to kill the security request task or it will get the event and my pair call will 'await' on the pair method until it times out. As you can see the solution is not ideal! But it works. |
Beta Was this translation helpful? Give feedback.
-
I am not sure how to get around this problem as I need to catch an event that may not occur. The
async await
is usually very convenient as youawait
for an event, but that assumes you know that it is coming. I don't want toawait
and event that might not come.I have a situation where I am writing a CCCD to a characteristic that is secured and I am not bonded. There are many possibilities.
One is that I get an insufficient authentication error. I can trap that GattError and initiate pairing and repeat the operation once bonded.
Second is that the library initiates pairing. The btstack does not, so I don't have to worry about it.
Third is that the device can issue a security request which the btstack does handle but I (and aioble) have no idea that it happened, It appears that the device finishes the operation as I get no error and I do not have to repeat the operation.
I do not want to
await
such an event as it might never happen. Some playing around with tasks maybe?Looking for ideas.
Beta Was this translation helpful? Give feedback.
All reactions