【问题标题】:Uncaught (in promise) : NotSupportedError: GATT Error Unknown未捕获(承诺中):NotSupportedError:GATT 错误未知
【发布时间】:2020-12-11 21:48:00
【问题描述】:

我正在尝试使用 Web 蓝牙 API 将长度为 490 的数据写入设备。当我尝试编写时,我得到 NotSupportedError: GATT Error Unknown。

我在安卓上使用 chrome 浏览器。

我的应用在 Angular 7 中,我正在使用 @types/web-bluetooth。

下面是代码:

navigator.bluetooth
.requestDevice({
filters: [{ name: this.deviceName }],
optionalServices: [this.GATT_SERVICE],
})
.then((device) => {
return device.gatt.connect();
})
.then((server) => {
return server.getPrimaryService(this.GATT_SERVICE);
})
.then((service) => {
this.gattService = service;
return this.gattService.getCharacteristic(this.GATT_CHAR);
})
.then((characteristic) => {
    characteristic.writeValueWithResponse(this.arraybufferdata);
})
.catch(async (err) => {
    console.log(err);
});

有人可以帮忙吗?

【问题讨论】:

    标签: bluetooth-gatt web-bluetooth


    【解决方案1】:

    这个问题与长度有关吗?你能在this.arraybufferdata 中用更少的字节重现错误吗?

    Nit:您可能希望返回 Promise 以便传播错误。

    .then((characteristic) => {
        return characteristic.writeValueWithResponse(this.arraybufferdata);
    })
    

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 2021-11-28
      • 2022-12-19
      • 2019-11-24
      • 2018-07-30
      • 2018-05-12
      • 2019-08-20
      • 2022-09-24
      相关资源
      最近更新 更多