Skip to content
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

connect does oblivious to connection failure. #7

Open
bj0 opened this issue Jan 23, 2018 · 5 comments
Open

connect does oblivious to connection failure. #7

bj0 opened this issue Jan 23, 2018 · 5 comments

Comments

@bj0
Copy link

bj0 commented Jan 23, 2018

If I try to connect to a device that is turned off, and wait with connect().await(), I will eventually get a StateChange from onConnectionStateChange with a status = 133 (GATT_ERROR) and newState = DISCONNECTED, but the await will never complete.

I currently wrap it in a withTimeout, but it would be nice if the connection error threw on the await, so I don't have to wait for the full timeout.

@bj0
Copy link
Author

bj0 commented Jan 23, 2018

after some more tries, it looks like I don't get that error every time, which is pretty odd

@LouisCAD
Copy link
Collaborator

LouisCAD commented Jan 23, 2018 via email

@bj0
Copy link
Author

bj0 commented Jan 23, 2018

I was getting nothing.

@LouisCAD
Copy link
Collaborator

This is expected since the device is not in range and powered on. The 133 GATT_ERROR is due to issues in the Bluetooth Stack however. As documented, it's your responsibility to handle connection status changes using the dedicated channel (so you can retry, or close the GattConnection object, cancelling the coroutines waiting on it). The sample shows how to properly use withTimeout to not let your app wait "forever". It allows you to specify exactly how much time you're willing to try to connect to a device that may no be in range at all.

@LouisCAD
Copy link
Collaborator

LouisCAD commented May 5, 2019

Did using withTimeout solve your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants