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

Should requestDevice() find devices by service UUID? #124

Closed
cwilling opened this issue Nov 18, 2023 · 16 comments · Fixed by #131
Closed

Should requestDevice() find devices by service UUID? #124

cwilling opened this issue Nov 18, 2023 · 16 comments · Fixed by #131

Comments

@cwilling
Copy link

I have some devices which advertise a service using a 128bit UUID generated at https://www.uuidgenerator.net/. The devices are successfully discovered in a browser using my own code based on webbluetooth samples at https://googlechrome.github.io/samples/web-bluetooth/index.html e.g.

navigator.bluetooth.requestDevice(options)

(where options are: {"filters":[{"services":["9f9c635f-3321-4490-9bae-c58572125000"]}]})

However if I try the heartrate.js example here but change the 'heart_rate' filter to my 128bit uuid i.e. change filters: [{ services: [ "heart_rate" ] }] to filters: [{ services: [ "9f9c635f-3321-4490-9bae-c58572125000" ] }], the devices are not discovered.

Should I be able to use arbitrary 128bit service uuids to filter available devices?

P.S. the devices are all found, along with a bunch or other devices, using the list.js example. I just want to limit the listing to those devices with my own service uuid.

Thanks for any assistance.

@cwilling cwilling changed the title Does requestDevice() find devices by service UUID? Should requestDevice() find devices by service UUID? Nov 18, 2023
@thegecko
Copy link
Owner

Thanks for raising this @cwilling

Can you confirm if your service UUID is advertised by your device (not just a primary service)?

This library currently only matches service UUID filters against advertised services and I've just tested this works.
However, the specification is confusing and could be seen as contradicting itself around this. So the implementation may be incorrect either in chrome or this library!

e.g.

https://webbluetoothcg.github.io/web-bluetooth/#scan-for-devices

  1. / 2. If device’s advertised Service UUIDs have a non-empty intersection with the set of Service UUIDs, add device to result and abort these sub-steps.

and:

https://webbluetoothcg.github.io/web-bluetooth/#matches-a-filter

  1. For each uuid in filter.services, if the UA has not received advertising data, an extended inquiry response, or a service discovery response indicating that the device supports a primary (vs included) service with UUID uuid, return mismatch.

@reillyeon What is the intent here? Should serviceuuid filters match advertised services and primary services?

@cwilling
Copy link
Author

Thanks for looking into this.

I can confirm the correct service UUID is being advertised (using Light Blue app on my phone).

Because my peripheral devices offer multiple services of which different clients may use different subsets, I use a separate UUID just for advertising. That way a client finding a device with correct UUID will know what real services the device offers (or connect to confirm). This advertising UUID has no corresponding service - it's purely for advertising. However from your discussion above, it seems expected that the advertised UUID also corresponds to an actual service. To test whether that makes a difference, I have now added a primary service with the same UUID as the advertising UUID. Unfortunately it has made no difference.

Other information:

  • for the ESP32 based peripheral devices, I use the NimBLE-Arduino library
  • I also have equivalent python code running on a Raspberry Pi Zero W

They're all advertising using the same UUID and are successfully filtered by that UUID using the browser application.

@thegecko
Copy link
Owner

Can you run the select example:

> node examples/selector.js

This should display all devices in range and any services they advertise. e.g. I see:

scanning...
select a device:
1: BBC micro:bit [pezut]
2: Garagentorantrieb
	Advertising: 669a9001-0008-968f-e311-6050405558b3

@cwilling
Copy link
Author

cwilling commented Nov 19, 2023

I previously copied examples/selector.js into the directory from where I want to run things (when they're working). Therefore I changed the line const Bluetooth = require("../").Bluetooth; to const Bluetooth = require('webbluetooth').Bluetooth;

chris@d8:~/src/dcdp-server/scripts/net$ node ./selector.js 
scanning...
select a device:
1: esp32-a0b765dcbdce
2: Unknown or Unsupported Device (EC:81:93:A6:60:6A)
3: LE-Indi Bose Micro
4: Unknown or Unsupported Device (68:C8:D1:6D:B9:52)
5: Unknown or Unsupported Device (45:79:A8:15:3E:1C)
6: Unknown or Unsupported Device (88:C6:26:CF:BC:F9)
7: esp32-ec6260bcaec2
8: esp32-348518438aa1
9: Unknown or Unsupported Device (48:F9:F3:EA:1D:07)
10: Unknown or Unsupported Device (46:D3:00:18:A9:17)
11: Unknown or Unsupported Device (6E:22:61:A6:85:F4)
12: Unknown or Unsupported Device (44:C6:5D:84:78:45)
13: Unknown or Unsupported Device (5D:37:A0:F3:F0:A4)
14: Unknown or Unsupported Device (46:6A:33:B2:F7:F4)
15: Unknown or Unsupported Device (74:13:1C:E5:D7:BD)
16: Unknown or Unsupported Device (6D:9A:2B:70:6A:E9)
17: Unknown or Unsupported Device (3F:5E:6C:80:76:66)
18: Unknown or Unsupported Device (56:92:E5:6F:AD:1F)
19: Unknown or Unsupported Device (68:00:60:51:EB:22)
20: Unknown or Unsupported Device (60:75:C3:16:4C:18)
21: Unknown or Unsupported Device (61:B5:AF:7E:C8:FA)
22: Unknown or Unsupported Device (74:92:70:DA:F7:70)
23: Unknown or Unsupported Device (65:0F:B6:64:95:78)
24: Unknown or Unsupported Device (49:B5:77:E4:EB:9C)
25: Unknown or Unsupported Device (70:29:BA:17:E5:C2)
26: Unknown or Unsupported Device (78:3D:7F:EA:FC:12)
27: Unknown or Unsupported Device (43:73:20:C3:87:E9)

If I then select device 1, I see all the three primary services including the 9f9c635f-3321-4490-9bae-c58572125000 service which is UUID being advertised:

connecting...
connected
service: 00001801-0000-1000-8000-00805f9b34fb
        └characteristic: 00002a05-0000-1000-8000-00805f9b34fb
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
service: 9f9c635f-3321-4490-9bae-c58572125000
service: 9f9c635f-3321-4490-9bae-c58572125001
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125002
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125003
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125006
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125007
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125008
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125009
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125010
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125011
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125012
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125014
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125015
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
service: 9f9c635f-3321-4490-9bae-c58572125100
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125101
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb
        └characteristic: 9f9c635f-3321-4490-9bae-c58572125102
                └descriptor: 00002902-0000-1000-8000-00805f9b34fb

disconnected

That all lines up with how the services have been setup for the peripherals.

Interestingly (not sure whether related to the main problem), I just noticed that the Raspberry Pi devices isn't listed even though it's found OK by the browser app.
EDIT: Raspberry Pi now found by selector.js - I had to set discoverable in peripheral code.

@thegecko
Copy link
Owner

Your selector output shows that the module can't see any services advertised by your device.

I wonder if this is an issue in the SimpleBLE module for your OS?

All my testing is done on MacOS, what host are you using?

@cwilling
Copy link
Author

So far, I have been trying with Linux.

I have access to a mac laptop which I've just tried. For all the esp32 & raspi devices, selector.js shows additional output "Advertising: " + the advertising UUID. Also, when I substitute that UUID into example/heartrate.js (replacing "heart_rate" filter), a relevant device is found i.e. filtering by UUID works as "advertised" on Mac but not Linux.

If I now need to investigate SimpleBLE, do you have any tips as to where to start looking?

@thegecko
Copy link
Owner

OK, this sounds like an OS specific issue with SimpleBLE.

@Symbitic can you support with investigating this shortcoming?

@Symbitic
Copy link
Contributor

Symbitic commented Nov 21, 2023

@thegecko Yes, this is an issue with SimpleBLE. More specifically, a problem with SimpleBlueZ: OpenBluetoothToolbox/SimpleBLE#135
I'm trying to look into it when I have time. One thing to help in the meantime: Service data before connecting doesn't work on Linux yet, but Machine data works on all platforms.

Edit: I finally made a PR in SimpleBLE to fix this. As soon as it's merged, should just need to update SimpleBLE used here.

@cwilling
Copy link
Author

cwilling commented Nov 21, 2023

Thanks @Symbitic that's great news - can't wait to try it out!

EDIT: in fact, I couldn't wait!

To test the PR OpenBluetoothToolbox/SimpleBLE#275, I changed local webbluetooth's SimpleBLE submodule url to point to @Symbitic bluez-servicedata-fix branch and rebuilt webbluetooth. Running examples/selector.js now shows (with multiple uninteresting results removed):

chris@d8:~/src/webbluetooth/examples$ node selector.js 
scanning...
select a device:
1: esp32-348518438aa1
        Advertising: 9f9c635f-3321-4490-9bae-c58572125000
...
4: esp32-a0b765dcbdce
        Advertising: 9f9c635f-3321-4490-9bae-c58572125000
5: esp32-ec6260bcaec2
        Advertising: 9f9c635f-3321-4490-9bae-c58572125000
...
18: raspberrypi-b827eb6a6efe
        Advertising: 9f9c635f-3321-4490-9bae-c58572125000

i.e. each of the relevant devices is now shown with its Advertising: entry. Also, substituting that UUID into examples/heartrate.js finds one of the devices advertising that UUID.

Mission accomplished!

Thanks again - I'll wait now until the PR is merged and a new webbluetooth npm module is published.

@thegecko
Copy link
Owner

A great example of people working together (and making my life easier)! thanks both.

@thegecko
Copy link
Owner

Will update webbluetooth when this is merged: OpenBluetoothToolbox/SimpleBLE#275

@Symbitic
Copy link
Contributor

Great! Any chance you can take a look at my PR while we wait?

@cwilling
Copy link
Author

cwilling commented Dec 1, 2023

@Symbitic's PR has been merged!

@thegecko
Copy link
Owner

thegecko commented Dec 1, 2023

The update run is here (it built):
https://github.com/thegecko/webbluetooth/actions/runs/7064331341

Perhaps use the artifacts on that to see if it fixes the issue?

@cwilling
Copy link
Author

cwilling commented Dec 2, 2023

I was able to pull from your repo and checkout the advertised-uuids branch and build a new build/Release/simpleble.node that works.

However I couldn't use the simpleble.node from the artifacts. Trying to use it complains about not finding a particular glibc version. I had the same problem with the previous version (before rebuilding) so since this isn't related to the original issue, I may raise a separate issue about it.

@thegecko
Copy link
Owner

Annoyingly I can't use the latest version of SimpleBLE with the advert fix due to this bug being introduced:

OpenBluetoothToolbox/SimpleBLE#277

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

Successfully merging a pull request may close this issue.

3 participants