收藏
回答

为什么wx.onBLECharacteristicValueChange()不执行?

wx.notifyBLECharacteristicValueChange({

                  state: true, // 启用 notify 功能

                  deviceId: that.data.deviceId,

                  serviceId: that.data.serviceId,

                  characteristicId: that.data.charaId,

                  success(res) {

                    console.log('notifyBLECharacteristicValueChange success', res.errMsg)

                  }

                })

                    function ab2hex(buffer) {

                      let hexArr = Array.prototype.map.call(

                        new Uint8Array(buffer),

                        function (bit) {

                          return ('00' + bit.toString(16)).slice(-2)

                        }

                      )

                      return hexArr.join('');

                      }

                    wx.onBLECharacteristicValueChange(function (res) {

                      console.log(`characteristic ${res.characteristicId} has changed, now is ${res.value}`)

                      console.log(ab2hex(res.value))


之前代码的characteristic里的write,read都为true,但writeDefault:false   wirtenoresponse:true 我不知道跟这个有没有关系,导致我notify是success和ok,writeBLECharacteristicValue也可以正常实现,但onble这个函数却不执行

回答关注问题邀请回答
收藏

1 个回答

  • GC
    GC
    2023-10-14

    跪求懂的人回复一下

    2023-10-14
    有用
    回复
登录 后发表内容