蓝牙写入接口writeBLECharacteristicValue执行时间长,平均2秒
发布于 4 年前 作者 juanfan 4638 次浏览 来自 分享

调用writeBLECharacteristicValue,发现成功的回调函数平均2秒多才会执行。哪位知道怎么回事吗

测试手机小米8 MIUI 10

      let buffer = new ArrayBuffer(1)
      let dataView = new DataView(buffer)
      dataView.setUint8(0,0x01);
      let timeStart = Date.now()
      wx.writeBLECharacteristicValue({
        // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
        deviceId:that.data.deviceId,
        // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
        serviceId:that.data.serviceUUID,
        // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
        characteristicId:that.data.ledCharacteristicId,
        // 这里的value是ArrayBuffer类型
        value: buffer,
        success (res) {
          let timeEnd = Date.now()
          let timeDiff =  timeEnd - timeStart 
          console.log('开关led成功 操作:',op,'执行时长:',timeDiff)
        },
        fail(res){
          console.log('开关led失败',)
        },
        complete(){
        }
      })

控制台日志

回到顶部