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