收藏
回答

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 个回答

  • Cjiang
    Cjiang
    2020-10-28

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html,麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点(具体到分钟)。

    2020-10-28
    有用
    回复 3
    • 金汤肥牛面
      金汤肥牛面
      2020-10-28
      https://developers.weixin.qq.com/s/KG5zzrms70ln ,微信号:Sun1412817183,今天的16:16
      2020-10-28
      回复
    • 金汤肥牛面
      金汤肥牛面
      2020-10-28
      华为Mate20X,微信7.0.19,EMUI10.1.0.166,Android10,基础库2.13.1
      2020-10-28
      回复
    • Cjiang
      Cjiang
      2020-11-02回复金汤肥牛面
      这种情况没法做兼容的,不过还是可以试试用wx.onBLECharacteristicValueChange监听特征值变化,因为也见过这种理论上不支持监听的情况实际上蓝牙设备还是会发包通知的。
      2020-11-02
      回复
登录 后发表内容
问题标签