ENABLE_NOTIFICATION_VALUE - API веб Bluetooth - PullRequest
0 голосов
/ 30 апреля 2018

Дескриптор характеристики конфигурации клиента (CCCD).

UUID - "00002902-0000-1000-8000-00805f9b34fb" / 'gatt.client_characteristic_configuration'.

Чтобы установить CCCD в коде Java для Android мы делаем:

public static final byte[] ENABLE_NOTIFICATION_VALUE = {0x01, 0x00};

BluetoothGattDescriptor descriptor =    characteristic.getDescriptor("00002902-0000-1000-8000-00805f9b34fb");
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

Как выполнить аналогичную настройку в коде JavaScript при использовании веб-API Bluetooth?

Моя версия на JavaScript:

.then(descriptors => {    
let queue = Promise.resolve();
 descriptors.forEach(descriptor => {
        switch (descriptor.uuid) {    
          case BluetoothUUID.getDescriptor('gatt.client_characteristic_configuration'):
           queue = queue.then(_ => descriptor.readValue()).then(value => {
              descriptorCache = descriptor;
            });
   ...

    var data = new Uint8Array([0x01, 0x00]);
    descriptorCache.writeValue(data);
    //descriptorCache.writeValue(new TextEncoder().encode(data));

завершается с ошибкой безопасности: - (

Uncaught (в обещании) DOMException: writeValue () вызывается для объекта из списка, помеченного как исключение-запись. https://webbluetoothcg.github.io/web-bluetooth/#attacks-on-devices

Я понимаю необходимость безопасности. Но в конце концов, многие устройства требуют предварительной настройки CCCD.

1 Ответ

0 голосов
/ 02 мая 2018

Вызов characteristic.StartNotifications() устанавливает CCCD для вас.

...