收藏
回答

onBLECharacteristicValueChange第二次连接蓝牙回调没有数据?

  低功耗蓝牙第一次连接执行readBLECharacteristicValue后onBLECharacteristicValueChange有数据回调
断开蓝牙再次连接。重新发送readBLECharacteristicValue后onBLECharacteristicValueChange不回调


wx.onBLECharacteristicValueChange(function (res) {
  /* console.log(res);
  console.log(that.reverseHexString(res.value)); */
  console.log(arrayBufferToString(res.value));

  // console.log('characteristic value comed:', characteristic)
  if (res.serviceId === "00660088-0001-0005-0010-F5FB94486B8D") {
    if (
      res.characteristicId === "00660088-0001-0005-0011-21BAC7B037C4"
    ) {
      deviceInfo.device_name = arrayBufferToString(res.value);
    } else if (
      res.characteristicId === "00660088-0001-0005-0012-BCECDCCE9A15"
    ) {
      deviceInfo.vendor_code = arrayBufferToString(res.value);
    } else if (
      res.characteristicId === "00660088-0001-0005-0013-5E6582E384F3"
    ) {
      deviceInfo.serial_code = arrayBufferToString(res.value);
    } else if (
      res.characteristicId === "00660088-0001-0005-0014-31BD010F80D3"
    ) {
      deviceInfo.hardware_version = arrayBufferToString(res.value);
    }
    bus.emit("deviceInfo", deviceInfo);
  }
  
});

readCharatorValue(deviceId, serviceId, characteristicId) {
    wx.readBLECharacteristicValue({
        // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
        deviceId,
        // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
        serviceId,
        // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
        characteristicId,
        success(res) {
            console.log(res, "读特征");
            // console.log('readBLECharacteristicValue:', res.errCode)
        },
        fail: (e) => {
            console.log(e);
        },
    });
},



回答关注问题邀请回答
收藏
登录 后发表内容