【问题标题】:Write length of 495 byte array to device using web bluetooth api使用网络蓝牙 api 将长度为 495 字节的数组写入设备
【发布时间】:2020-10-14 13:52:16
【问题描述】:

我正在调用一个 python api 端点,它将向我发送要写入设备的数据。接收到的数据是加密格式,我正在使用下面将其转换为字节数组

 let codePoints = [];

 for (let i = 0; i < encData.length; i++) {
   codePoints.push(encData.codePointAt(i));
 }

 const arraybufferdata = Uint8Array.from(codePoints);

我正在尝试使用以下代码编写此字节数组:

characteristic
.writeValueWithoutResponse(arraybufferdata)
.then(() => {
  console.log("successfully written to the device");
});

我收到以下错误:

我也尝试通过将字节数组分成如下块来编写:

writeOut(data, start) {
 if (start >= data.byteLength) {
   console.log("successfully written to the device");
   return;
 }

this.mychar
  .writeValueWithoutResponse(data.slice(start, start + 256))
  .then(() => {
     this.writeOut(data, start + 256);
   });
}

writeBuffer(data, start) {
   this.writeOut(data, start);
}

this.writeBuffer(arraybufferdata, 0);

这也是抛出错误。可能是什么问题?设备也不接受要写入的数据。

UI 框架:Angular 7 操作系统:Windows 10 浏览器:Chrome 85

请帮忙!

【问题讨论】:

    标签: bluetooth-lowenergy web-bluetooth


    【解决方案1】:

    发现问题:

    我写错了特征! (捂脸)

    现在可以使用了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-06
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多