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

Failed to connect when device is already connected #29

Open
jlsjonas opened this issue Jan 20, 2021 · 7 comments
Open

Failed to connect when device is already connected #29

jlsjonas opened this issue Jan 20, 2021 · 7 comments

Comments

@jlsjonas
Copy link

jlsjonas commented Jan 20, 2021

As per the Prerequisites

The desk should be connected and paired to the computer.

However, I was unable to execute a command until I specifically DISCONNECTED the device.

My theory: When f.e. executing bluetoothctl I'm directly on the desk already, so the script is likely trying to connect the desk with another device; instead of just doing its thing

As being connected already would avoid scanning & connecting; thus significantly reducing execution time (especially for simple commands) I'd propose to actually check if we're already connected, and just communicate directly in that case, instead of trying to scan & connect

OS: Ubuntu 20.04
bleak is using bluez as backend (in my case)
edit: regarding timing, a no-op (simple read) takes 4-5 seconds currently

newAM added a commit that referenced this issue Jan 23, 2021
@newAM
Copy link
Owner

newAM commented Jan 23, 2021

Does the branch issue/29 fix this?

I am on a new PC without integrated bluetooth, cannot test this myself until I get a dongle.

newAM added a commit that referenced this issue Jan 23, 2021
@jlsjonas
Copy link
Author

jlsjonas commented Jan 25, 2021

@newAM sadly enough it doesn't, it gets stuck on the listing/scanning step in bluez; it seems that the scan doesn't return already connected devices (which makes sense I guess); disconnecting from the desk (even while it's already scanning, as long as not all tries have been exhausted) makes it connect to it and report back.

Sadly enough my python knowledge is quite limited, so I'm not how to help exactly, but it seems that the issue would be in here https://github.com/newAM/idasen/blob/master/idasen/__init__.py#L234

edit: or an issue with BleakClient itself? https://github.com/newAM/idasen/blob/master/idasen/__init__.py#L84

edit2: looks like it's a known limitation of Bleak hbldh/bleak#367 (comment)
the fix is that you're supposed to ask Bluez over DBus yourself

@newAM
Copy link
Owner

newAM commented Jan 30, 2021

The last person said:

I thought Bleak would ask BlueZ over DBus whether the connection exists already but I am okay to do it myself.

Would you know how to do that?

My bluez/dbus experience is limited, I chose bleak simply because it looked like the only bluetooth back-end receiving regular bugfixes.

Edit: Also, sorry for the slow replies, work has been keeping me rather busy on weekdays.

@jlsjonas
Copy link
Author

Sadly enough not really 😅
As I mentioned my python knowledge in general is quite limited; I was considering extending one of the node.js-based versions (with IFTTT/google integration) but it seemed like they all had significant problems during quick tests at least.

No problem, work is keeping me quite busy too

@jlsjonas
Copy link
Author

https://stackoverflow.com/a/16129705/620141 might be useful for a native connection? (The tutorial in particular)

@newAM
Copy link
Owner

newAM commented Jan 31, 2021

Huh, it appears the python socket interface will also just work.
All that looks pretty spartan though, and I don't know as much about host-side BLE as I would like 😅, will probably be a while before I get to it.

@jlsjonas
Copy link
Author

jlsjonas commented Feb 5, 2021

I've just completed a PoC in Node connecting the desk through IFTTT with google assistant, and I must say it's working AMAZINGLY so far 😎
I'll be posting the code soon after some polishing work, in case you're interested

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

No branches or pull requests

2 participants