WebBluetoothCG / web-bluetooth

Bluetooth support for the Web.
http://www.w3.org/community/web-bluetooth/
Other
1.39k stars 188 forks source link

No services matching UUID help #513

Open Cegard opened 4 years ago

Cegard commented 4 years ago

Hello Everyone:

I've been playing around with WebBluetooth since a couple of days ago, for that I've been using my phone with the nRF Connect app as a GATT Server, and I've been using the next function to attempt the connection with the phone:

        async function onButtonClick() {
            let device = await navigator.bluetooth.requestDevice({
                acceptAllDevices: true,
                optionalServices: [ 0x180D ]
            });
            let server = await device.gatt.connect();
            console.log(server);
            let service = await server.getPrimaryService(0x180D);
            console.log(service);
        }

I've been trying the services: 0x181C, health_monitor, heart_rate, but the result I'm getting is: DOMException: No Services matching UUID 000180-0000-1000-8000-00805f9b34fb; and with the service "0000aaa0-0000-1000-8000-aabbccddeeff" I get DOMException: Origin is not allowed to access the service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options.

Any ideas of what could be happening, or another way to test this?

Thanks in advance.

odejesush commented 4 years ago

To be able to access the services, you need to specify them in the filters property of the RequestDeviceOptions or in optionalServices. In your example, you're using acceptAllDevices: true, so you'll need to add the services that you want to access to optionalServices in order to get permission to access them.

Cegard commented 4 years ago

Hello again:

I managed to get to the service (and to the characteristic after that), the solution was adding another service in the optionalServices field and then ask for just one of them with server.getPrimaryService, something like this:

        async function onButtonClick() {
            let device = await navigator.bluetooth.requestDevice({
                acceptAllDevices: true,
                optionalServices: [0x1801, "162348d9-d5a8-4870-8086-8e152fd06a92"]
            });
            let server = await device.gatt.connect();
            console.log(server);
            let service = await server.getPrimaryService("162348d9-d5a8-4870-8086-8e152fd06a92");
            console.log("serviced");
            console.log(service);
        }   

If I only specify one of them in optionalServices and try to retrieve it, it won't work, is this the expected behavior?

**Edit: For this to suceed I had to use a custom bluetooth device (raspberry), when using nRF on my phone with the two services solution it just stays waiting for the connection, it doesn't show any message, just keeps waiting and waiting.

odejesush commented 4 years ago

Yes, if it's not specified, the site does not receive permission to access the service. This is intended behavior.

On Mon, Sep 7, 2020, 11:40 Eduardo Galeano notifications@github.com wrote:

Hello again:

I managed to get to the service (and to the characteristic after that), the solution was adding another service in the optionalServices field and then ask for just one of them with server.getPrimaryService, something like this:

  async function onButtonClick() {
      let device = await navigator.bluetooth.requestDevice({
          acceptAllDevices: true,
          optionalServices: [0x1801, "162348d9-d5a8-4870-8086-8e152fd06a92"]
      });
      let server = await device.gatt.connect();
      console.log(server);
      let service = await server.getPrimaryService("162348d9-d5a8-4870-8086-8e152fd06a92");
      console.log("serviced");
      console.log(service);
  }   

If I only specify one of them in optionalServices and try to retrieve it, it won't work, is this the expected behavior?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/WebBluetoothCG/web-bluetooth/issues/513#issuecomment-688428971, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXTX3MMT2I6ICWJCNHICA3SEUEGPANCNFSM4Q3GAE5Q .

zhangzhoufei commented 4 years ago

The same problem as the originator: error: DOMException: Origin is not allowed to access the service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options.

It's been bothering me for a long time Please help me.

navigator.bluetooth.requestDevice({
     filters: [ 
        { namePrefix: 'play' } 
    ],
    optionalServices: [ "162348d9-d5a8-4870-8086-8e152fd06a92"]
}).then(device => {
    console.log('Got device:', device.name);
    return device.gatt.connect();
})
.then(server => {
    return server.getPrimaryService("162348d9-d5a8-4870-8086-8e152fd06a92");
})
.then(service => {

})
.then(characteristic => {

})
.then(value => {
    value = value.buffer ? value : new DataView(value);
    console.log('Battery percentage:', value.getUint8(0));
})
.catch(exception => {
    console.log(exception);
});
Cegard commented 4 years ago

Hey @zhangzhoufei, sorry for the delay, you could try to add another service (besides the one you need to access) in the optionalServices field, or deleting that field and use the getPrimaryServices function. For me both of these solitions are workarounds, but they worked for me.

dtknowlove commented 4 years ago

i get the same error,this is my code:

            let device = await navigator.bluetooth.requestDevice({
                filters: [{
                    namePrefix: 'Pai',
                    // services: ['0000fff0-0000-1000-8000-00805f9b34fb','0000fff1-0000-1000-8000-00805f9b34fb','0000fff2-0000-1000-8000-00805f9b34fb','0000fff3-0000-1000-8000-00805f9b34fb'],
                    optionalServices: ['0000fff0-0000-1000-8000-00805f9b34fb']
                }]
            });
            console.log(1);
            console.log('Got device:', device.name);
            console.log('id:', device.id);
            let server = await device.gatt.connect();
            console.log(server);
            await delay(10000);
            console.log(2);
            let services = await server.getPrimaryService('0000fff0-0000-1000-8000-00805f9b34fb')
            console.log(3,services);
            let characteristic = await services.getCharacteristic('0000fff0-0000-1000-8000-00805f9b34fb');
            console.log(characteristic);

Any ideas of what could be happening, or another way to fix this?

dvmarinoff commented 3 years ago

Hi, I am getting the same error message while trying to get the battery service (0x180F) of a Tacx Heart Rate Belt. nRF Connect shows the service is there and can read it's Battery Level characteristic, but:

No Services matching UUID 0000180f-0000-1000-8000-00805f9b34fb found in Device.

Meanwhile I am able to successfully work with the Device Information Service (0x180A), and Heart Rate Service (0x180D).

Here is the log from nRF Connect:

========================================== nRF Connect, 2020-11-25 Tacx HRB 20483 (F1:17:11:FF:45:F2) I 14:53:06.050 [Server] Server started V 14:53:06.058 Heart Rate (0x180D)

reillyeon commented 3 years ago

@dvmarinoff, please file an issue on crbug.com for this problem and tag it with the Blink>Bluetooth complement. If you can please test on a macOS or Windows device as well.

dvmarinoff commented 3 years ago

added Issue 1155044

milesfrain commented 3 years ago

I'm observing that chrome://bluetooth-internals only lists 8 of 10 available services. The missing services are battery_service 0x180f and generic_access 0x1800. Both of these services appear on nRF Connect and via BlueZ CLI.

sudo gatttool -b 84:2E:14:31:BB:40 -I
[84:2E:14:31:BB:40][LE]> connect
Attempting to connect to 84:2E:14:31:BB:40
Connection successful
[84:2E:14:31:BB:40][LE]> primary
attr handle: 0x0001, end grp handle: 0x0008 uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0009, end grp handle: 0x000d uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x000e, end grp handle: 0x001a uuid: 0000180a-0000-1000-8000-00805f9b34fb
attr handle: 0x001b, end grp handle: 0x001e uuid: 0000180f-0000-1000-8000-00805f9b34fb
attr handle: 0x001f, end grp handle: 0x0021 uuid: ec61a454-ed00-a5e8-b8f9-de9ec026ec51
attr handle: 0x0022, end grp handle: 0x002b uuid: 00001815-0000-1000-8000-00805f9b34fb
attr handle: 0x002c, end grp handle: 0x0034 uuid: f598dbc5-2f00-4ec5-9936-b3d1aa4f957f
attr handle: 0x0035, end grp handle: 0x0037 uuid: 1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0
attr handle: 0x0038, end grp handle: 0x0041 uuid: a4e649f4-4be5-11e5-885d-feff819cdc9f
attr handle: 0x0042, end grp handle: 0xffff uuid: 0000181a-0000-1000-8000-00805f9b34fb

Version Info:

lsb_release -d
Description:    Ubuntu 20.04.1 LTS
bluetoothd -v
5.53
milesfrain commented 3 years ago

Turns out that a default BlueZ plugin was stealing battery_service 0x180f. The fix is to disable the plugin with the -P battery flag. More details on the solution are described in https://github.com/WebBluetoothCG/ble-test-peripheral-android/issues/95#issuecomment-743930669

Now chrome successfully detects battery_service 0x180f :tada:

travisghansen commented 7 months ago

I ran into this issue when developing against a custom BLE service (service is running on another linux node). After adding characteristics to the service it seems that triggered this issue.

To resolve I have consistently been able to do the following (on the web bluetooth node):

rm -rf /var/lib/bluetooth/*
systemctl restart bluetooth.service