收藏
回答

wx.writeBLECharacteristicValue接口频繁报10008错误?

业务场景中:不需要订阅读完特征值之后直接调用wx.writeBLECharacteristicValuea这个接口
d代码如下:
onLoad: function (options{
    this.setData({
      curDeviceId: options.deviceId
    })
    this.handleGetServices()


    //全局网络监听器
    wx.onBLECharacteristicValueChange(res => {
      console.log(`CONNECTION Page  on NetworkStatusBLECharacteristicValueChange res:`, res)
    })
  },


  editName(){
    console.log("Ssssssssssss")
    this.setData({
      showModal:true
    })
  },
  hideModal(){
    this.setData({
      showModal:false
    })
  },
  updateName(){


  },


  handleGetServices() {
    let that = this
    console.log("CONNECTION Page handleGetServices"this.data.curDeviceId)
    wx.getBLEDeviceServices({
      deviceId: this.data.curDeviceId,
      success: (res) => {
        console.log(`CONNECTION Page  getBLEDeviceServices res:`, res)
        that.handleGetCharacteristics()
      },
      fail: (error) => {
        console.error(`CONNECTION Page  getBLEDeviceServices error:`, error)
      }
    })
  },
  handleGetCharacteristics() {
    console.log(`CONNECTION Page handleGetCharacteristics`this.data.curDeviceId)
    wx.getBLEDeviceCharacteristics({
      deviceId: this.data.curDeviceId,
      serviceId: '0000180A-1111-2222-0000-123456780000',
      success: (res) => {
        console.log(`CONNECTION Page  getBLEDeviceCharacteristics res:`, res)
        this.handleReadCharacteristics()
      },
      fail: (error) => {
        console.error(`CONNECTION Page  getBLEDeviceCharacteristics error:`, error)
      }
    })
  },
  handleReadCharacteristics() {
    console.log(`CONNECTION Page handleReadCharacteristics`)
    wx.readBLECharacteristicValue({
      deviceId: this.data.curDeviceId,
      serviceId: '0000180A-1111-2222-0000-123456780000',
      characteristicId: 'DDDDEEEE-1111-2222-0000-123456780005',
      success: (res) => {
        console.log(`CONNECTION Page  readBLECharacteristicValue res:`, res)
        // this.handleNotifyCharacteristics()
      },
      fail: (error) => {
        console.error(`CONNECTION Page  readBLECharacteristicValue error:`, error)
      }
    })
  },
  handleNotifyCharacteristics() {
    console.log(`CONNECTION Page handleNotifyNetworkStatusCharacteristics`)
    wx.notifyBLECharacteristicValueChange({
      deviceId: this.data.curDeviceId,
      serviceId: '0000180A-1111-2222-0000-123456780000',
      characteristicId: 'DDDDEEEE-1111-2222-0000-123456780005',
      state: true,
      success: (res) => {
        console.log(`CONNECTION Page  notifyNetworkStatusBLECharacteristicValueChange res:`, res)
      },
      fail: (error) => {
        console.error(`CONNECTION Page  notifyNetworkStatusBLECharacteristicValueChange error:`, error)
      }
    })
  },


  enterKey(e: any) {
    let keyVal = e.currentTarget.dataset.key
    console.log("用户按键", keyVal)
    let value = this.string2buffer(keyVal)
    console.log("转成arrayBuffer字符串",value)
    this.handleWriteBLECharacteristic(value)
  },
  handleWriteBLECharacteristic(bufferVal: ArrayBuffer) {
    console.log("开始写特征值===========",bufferVal,wx.getStorageSync("curDeviceId"))
    wx.writeBLECharacteristicValue({
      deviceId: wx.getStorageSync("curDeviceId"),
      serviceId: '0000180A-1111-2222-0000-123456780000',
      characteristicId: 'DDDDEEEE-1111-2222-0000-123456780005',
      value: bufferVal,
      success: (res) => {
        console.log('writeBLECharacteristicValue success', wx.getStorageSync("curDeviceId"), res)
        // this.setData({
        //   isInitPage: false
        // })
        if (res.errCode == 0 || res.errCode == -1) {
        }
      }, 
      fail: (error: any) => {
        console.log('writeBLECharacteristicValue error', error)
      },
      complete:(value:any)=>{
        console.log('writeBLECharacteristicValue complete', value)
      }
    })
  },
回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2022-06-15

    你好,10008是有再细分的,具体可以看errMsg;这类错误都是系统直接回调错误,不是小程序逻辑上增加的;具体到writeBLECharacteristicValue,就是write这个动作系统接口返回fail了;偶现的情况,建议延后一会重试。

    2022-06-15
    有用
    回复 3
    • 王旭
      王旭
      2022-08-11
      errMsg=Unlikely error  这种错误是对应什么情况
      2022-08-11
      回复
    • 对方不在输入
      对方不在输入
      2023-03-24回复王旭
      请问你有解决吗
      2023-03-24
      回复
    • 残月星空
      残月星空
      2023-06-17
      设备第一次发数据 手机正常接收 手机正常发送给设备后 再次发送数据  必现10008
      2023-06-17
      回复
登录 后发表内容