getDevices() returns an empty list on Windows 11
This code
const bluetooth = new Bluetooth({ deviceFound });
const device = await bluetooth.getDevices();
returns an empty list and this message in the console
[INFO] SimpleBLE: D:\a\webbluetooth\webbluetooth\SimpleBLE\simpleble\src\backends\windows\Utils.cpp:33 in initialize_winrt: CoGetApartmentType: cotype=-1, qualifier=0, result=800401F0 [INFO] SimpleBLE: D:\a\webbluetooth\webbluetooth\SimpleBLE\simpleble\src\backends\windows\Utils.cpp:41 in initialize_winrt: RoInitialize: result=0
The PC runs Windows 11 and has a built in Bluetooth adapter Any ideas how to fix? Thank you
If possible, can you see if the underlying bluetooth engine works on your system?
https://github.com/OpenBluetoothToolbox/SimpleBLE
Unfortunately I'm not set up to do that at the moment so it will take time. Looking at the SimpleBLE supported platforms it says "Windows 10+" but does not explicitly list Windows 11 so I'm suspicious. I'll try on Windows 10 and let you know Thank you!
Windows 10 should work, I test on it :)
I am able to reproduce, the same code for discovering at least works from the normal navigator bluetooth implementation https://googlechrome.github.io/samples/web-bluetooth/get-devices.html
I am able to reproduce, the same code for discovering at least works from the normal navigator bluetooth implementation https://googlechrome.github.io/samples/web-bluetooth/get-devices.html
Welp, disregard that, I misunderstood the design pattern and was trying to extend the calls into an emitter pattern. Discovered that You need to call bluetooth.requestdevice to populate the devices, then getDevices()
Bump! Same happening here.
I did try simplepyble, that also uses SimpleBLE, and worked; but I do need a JS implementation...
I need to see some reproducer code for this issue, please
Hi @FLATT-Dev, I ran @chdh test case with 3.3.2 on Win 11 Pro 24H2 and getDevices() behaves as it should there. See #331. What exact version of Win are you using?
@jubesab getDevices() returns the devices array.
The only place where an entry is added to this array is line 302:
devices.push(bluetoothDevice);
This line is only executed when the condition of the IF statement is met:
if (this.options?.allowAllDevices || this.allowedDevices.has(deviceInfo.id)) {
allowAllDevices is not set in my test case for this issue and the allowedDevices set is empty. I don't understand how this could ever work.