【问题标题】:JS Web Bluetooth API: Error startNotification() not supportedJS Web 蓝牙 API:不支持错误 startNotification()
【发布时间】:2020-02-13 04:09:24
【问题描述】:

每当我调用 startNotifications() 时,我都会遇到“Gatt 错误:不支持”。我查看了兼容性和实现页面,看起来应该实现这个功能(我在 Windows 10 上使用 Chrome 80,我还在 chrome 中启用了实验性网络功能,但这并没有解决它)。我无法弄清楚为什么错误不断弹出。

代码如下:

function connect(){
    return my_device.gatt.connect()
    .then(server => {
        console.log("Getting Service...");
        return server.getPrimaryService(0x1800);
    })
    .then(service => {
        console.log("Getting Characteristic...");
        return service.getCharacteristic("00002a00-0000-1000-8000-00805f9b34fb");
        //return service.getCharacteristic("00002a01-0000-1000-8000-00805f9b34fb");
    })
    .then(characteristic => {
        console.log("Characteristic Type: " + characteristic);
        my_character = characteristic;
        console.log("Before Notification");
        return my_character.startNotifications().then(_ => {
          console.log('Notifications started');
          my_character.addEventListener('characteristicvaluechanged',
              handleNotifications);
        });
    })
}

【问题讨论】:

    标签: javascript web-bluetooth


    【解决方案1】:

    我想通了。我使用了错误的特征 uuid 并获得了一个不接受通知的频道。令人困惑的是,它没有给出通常的“不允许”错误,而是吐出“不支持”错误。

    你可以通过characteristic.properties查看一个特性支持的属性。[#你要检查的东西]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多