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

Can't successfully connect BLE devices on Linux #12

Open
MrShinyAndNew opened this issue Oct 17, 2024 · 6 comments
Open

Can't successfully connect BLE devices on Linux #12

MrShinyAndNew opened this issue Oct 17, 2024 · 6 comments

Comments

@MrShinyAndNew
Copy link

I'm trying to connect a Lego Powered Up remote using node-poweredup. I've overridden its dependency to use @stoprocent/noble, but the behaviour is very poor and inconsistent. I think there are still unresolved issues, but I'm not sure how to debug this any further.

The sample program on the noble screen, or the basic sample node-poweredup program both show the same symptoms - they fail to successfully connect to the BLE device 19 times out of 20. Most of the time the program does nothing; sometimes it gives an error "already connected".

I have tried using strace to inspect the system calls and one thing I noticed is that the connect() system call sometimes takes 40s and failes with "Connection refused" - of course my BLE device has given up attempting to connect long before 40s is up.

Example:
connect(24, {sa_family=AF_BLUETOOTH, l2_psm=htobs(0 /* L2CAP_PSM_??? */), l2_bdaddr=07:d0:99:f1:34:a4, l2_cid=htobs(L2CAP_CID_ATT), l2_bdaddr_type=BDADDR_LE_PUBLIC}, 14) = -1 ECONNREFUSED (Connection refused)

@stoprocent
Copy link
Owner

@MrShinyAndNew It's very little details to work with. I can try something but I only have duplo ble train that is anything close to this. One thing I can tell you is that I took over noble because I'm using it in production environments at work and it has been super stable for us. We are using it all over the place. What is the BLE hci you are using? Do you have any other BLE dongle you can use and see if its the same? Im making thousands request everyday in CI/CD and I do get connection issues but I would say it's like 1 per 10k

@stoprocent
Copy link
Owner

stoprocent commented Oct 18, 2024

So I did a little digging and I think it could be related to BLE you have either built in or dongle. I have 2 dongles one is BLE 5.3 and the other one is 4.1. With the 5.3 one I do have some inconsistency but 4.1 is like this:

IMG_0033.MOV

By this I mean its connecting every single time. No issues

@MrShinyAndNew
Copy link
Author

I'm using a Dell XPS notebook from 2017. I'm not sure how to determine what kind of bluetooth it has. lspci lists a Qualcomm Atheros QCA6174 network controller and lsusb lists a Qualcomm Atheros wireless device but doesn't indicate if it's the Bluetooth controller or not.

I didn't mean to imply that the noble library doesn't work at all :) but before the kernel changes, everything worked perfectly on this notebook. I don't mind diving in to debug or otherwise dig in to this problem but I don't know where to look - I'm not really an expert in bluetooth. I can try with a different notebook, but it will take some time to get back to you.

@MrShinyAndNew
Copy link
Author

MrShinyAndNew commented Oct 21, 2024

I've tested on my other notebook with the same results. lspci shows an Intel Dual Band Wireless-AC 3168NGW and lsusb shows Intel Corp. Wireless-AC 3168 Bluetooth. Both of these devices worked before and they're both fairly old so there's nothing new and exotic in them.

I realize this bug report doesn't have much actionable detail - if there's any test I can run I'd love to help get to the bottom of this.

@stoprocent
Copy link
Owner

If you can export DEBUG=* and run connection attempt and paste the log here

@MrShinyAndNew
Copy link
Author

Okay, here are 4 tests I ran, listed here in the order I ran them. The first two use the node-poweredup library with an override (I've verified it's pulling in the expected noble version). The second two just use plain noble. The address for the remote is "a4:34:f1:99:d0:07".

This one, the Lego remote appeared to connect (solid indicator light) right away, but the test program didn't emit the "discovered" event.
connected_but_not_discovered.txt

This one emitted the "discovered" event but then never connected
discovered_but_not_connected.txt

This one instantly failed with "already connected"
noble_already_connected.txt

This one didn't connect.
noble_not_connected.txt

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