收藏
回答

notifyBLECharacteristicValueChange调用报错?

{"errCode":10008,"errMsg":"notifyBLECharacteristicValueChange:fail:no descriptor"}

华为Mate20X,微信7.0.19,EMUI10.1.0.166,Android10,基础库2.13.1

getBLEDeviceServices(deviceId) {
    let that = this
    wx.getBLEDeviceServices({
      deviceId,
      success(res) => {
        for (let i = 0; i < res.services.length; i++) {
          let serviceId = res.services[i].uuid
          wx.getBLEDeviceCharacteristics({
            deviceId,
            serviceId,
            success(res) => {
              for (let j = 0; j < res.characteristics.length; j++) {
                let item = res.characteristics[j]
                if (item.properties.read) {}
                if (item.properties.write) {}
                if (item.properties.notify || item.properties.indicate) {
                  wx.notifyBLECharacteristicValueChange({
                    deviceId,
                    serviceId,
                    characteristicId: item.uuid,
                    statetrue,
                  })
                }
              }
            },
            fail(res) {
              console.error('getBLEDeviceCharacteristics', res)
            }
          })

          wx.onBLECharacteristicValueChange((characteristic) => {
            console.log("characteristicId:" + res.characteristicId)
            console.log("serviceId:" + res.serviceId)
            console.log("deviceId" + res.deviceId)
            console.log("Length:" + res.value.byteLength)

            // const idx = inArray(this.data.chs, characteristic.characteristicId)
            // const data = {}
            // if (idx === -1) {
            //   data[`ser[${this.data.chs.length}]`] = {
            //     uuid: characteristic.characteristicId,
            //     value: ab2hex(characteristic.value)
            //   }
            // } else {
            //   data[`chs[${idx}]`] = {
            //     uuid: characteristic.characteristicId,
            //     value: ab2hex(characteristic.value)
            //   }
            // }
            // this.setData(data)
          })
          
        }
        that.setData(services)
        this.setData({
            ser: services
          })
          console.log(services)
      },
    })
  },
  writeBLECharacteristicValue() {
    let that = this
    // let dataView = new DataView(buffer)
    // dataView.setUint8(0, Math.random() * 255 | 0)
    console.log(that.data.text)
    console.log(that.data.ser)
    wx.writeBLECharacteristicValue({
      deviceId: that.data.deviceId,
      serviceId"10000000-0000-0000-0000-000000000000",
      characteristicId"12000000-0000-0000-0000-000000000000",
      valuenew ArrayBuffer(that.data.text),
    })
  },
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签