收藏
回答

微信小程序蓝牙监听特征值的value分包了啊,怎么解决?

// 操作之前先监听,保证第一时间获取数据

      wx.onBLECharacteristicValueChange((characteristic) => {

        console.log(characteristic)

        const idx = dataTransform.inArray(this.data.chs, 'uuid', characteristic.characteristicId)

        const data = {}

        if (idx === -1{

          data[`chs[${this.data.chs.length}]`= {

            uuid: characteristic.characteristicId,

            value: dataTransform.ab2hex(characteristic.value)

          }

        } else {

          data[`chs[${idx}]`= {

            uuid: characteristic.characteristicId,

            value: dataTransform.ab2hex(characteristic.value)

          }

        }

        // data[`chs[${this.data.chs.length}]`] = {

        //   uuid: characteristic.characteristicId,

        //   value: ab2hex(characteristic.value)

        // }

        this.setData(data)

        console.log(characteristic.value)

        eventBus.emit('bleDataChanged', dataTransform.ab2hex(characteristic.value));

        console.log(data)

      })


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

1 个回答

  • 智能回答 智能回答 该问答由AI生成
    03-29
    有用
登录 后发表内容