1

Eddystone ビーコンと対話する Web アプリを作成しようとしています。ビーコンはアプリの URL をアドバタイズし、サービスと 2 つの特性を公開します。

私のデバイスには、Linux の gatttool で示されるように、次のサービスと特性があります。

$ gatttool -I 
[00:1A:7D:DA:71:15][LE]> connect 00:1A:7D:DA:71:15 
Attempting to connect to 00:1A:7D:DA:71:15 
Connection successful 
[00:1A:7D:DA:71:15][LE]> primary 
attr handle: 0x0001, end grp handle: 0x0005 uuid: 00001800-0000-1000-8000-00805f9b34fb 
attr handle: 0x0006, end grp handle: 0x0009 uuid: 00001801-0000-1000-8000-00805f9b34fb 
attr handle: 0x000a, end grp handle: 0x0012 uuid: ba42561b-b1d2-440a-8d04-0cefb43faece 
[00:1A:7D:DA:71:15][LE]> characteristics 
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb 
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb 
handle: 0x0007, char properties: 0x20, char value handle: 0x0008, uuid: 00002a05-0000-1000-8000-00805f9b34fb 
handle: 0x000b, char properties: 0x1a, char value handle: 0x000c, uuid: 6bcb06e2-7475-42a9-a62a-54a1f3ce11e6 
handle: 0x000f, char properties: 0x1a, char value handle: 0x0010, uuid: 6bcb06e2-7475-42a9-a62a-54a1f3ce11e5 
[00:1A:7D:DA:71:15][LE]

ここの例から作業しています

if (navigator.bluetooth) {
  console.log("bluetooth found");
  navigator.bluetooth.requestDevice({
    filters: [{
      services: ['ba42561b-b1d2-440a-8d04-0cefb43faece']
    }]
  })
  .then(device => {
    bluetoothDevice = device;
    console.log(device.name);
    console.log(device.uuids);
    device.connectGATT();
  })
  .then(server => {
    return server.getPrimaryService('ba42561b-b1d2-440a-8d04-0cefb43faece');
  })
  .then(service => {
    return service.getCharacteristic('6bcb06e2-7475-42a9-a62a-54a1f3ce11e6');
  })
  .then( characteristic => {
    var toggleOn = new Uint8Array([1]);
    return characteristic.writeValue(toggleOn);
  })
  .catch(error => { 
    console.log("error:- " + error); 
  });
}

このコードはデバイスを検出しません。を使用するようにフィルターを変更するnamePrefixと、デバイスが検出されますが、関心のあるサービスではなく、1 つのサービスのみが一覧表示されます。

発見と適切なサービスの検索で私が間違っていることを知っている人はいますか?

4

1 に答える 1

2

このfilters引数は、デバイスの gatt サーバーによって実際に公開されるサービスではなく、主にデバイスが送信する広告パケットに基づいてデバイスをフィルタリングします。そのため、ビーコンが URL とその名前をアドバタイズするだけの場合、特定のサービス UUID をフィルタリングしても見つけられない可能性があります。

「しない」ではなく「ありそうにない」と言ったのは、デバイスに一度接続したことがある場合、システムはデバイスが実際に公開している一連のサービスをキャッシュし、それらを使用してフィルターに一致させる可能性があるためです。

引数に切り替える場合はnamePrefix、 で使用するすべてのサービスを忘れずにリストする必要がありますoptionalServices

navigator.bluetooth.requestDevice({
  filters: [{
    namePrefix: 'something',
  }],
  optionalServices: ['ba42561b-b1d2-440a-8d04-0cefb43faece']
});
于 2016-03-17T07:13:12.827 に答える