0

每当我调用 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);
        });
    })
}
4

1 回答 1

2

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

您可以通过characteristic.properties检查特征支持的属性。[#thing you want to check]

于 2020-02-12T20:09:24.800 回答