writeBLECharacteristicValue 调用问题需要有间隔吗?
发布于 7 年前 作者 gyi 8724 次浏览 来自 官方Issues

在分包发送的情况下

调用writeBLECharacteristicValue

Android发送数据,目标设备接收到的数据是乱序的

IOS则无此问题。

代码如下:

export const writeBLECharacteristicValue = async ({ value, deviceId, serviceId, characteristicId }) => {
  try {
    let temBuffer = value;
    let resp;
    while (temBuffer.byteLength > 0) {
      let ab = temBuffer.slice(0, 20);
      let send_resp = await toPromise(wx.writeBLECharacteristicValue, { deviceId, serviceId, characteristicId, value: ab });
      if (send_resp.errCode === 0) {
        temBuffer = temBuffer.slice(20);
      }
      resp = send_resp;
    }
    return resp;
  } catch (error) {
    throw error;
  }
}
回到顶部