【发布时间】: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