服务商代开发
小程序
基础
连接微信
办公
JS-SDK
基础
连接微信
办公
服务商代开发
客户端API
JS-SDK
蓝牙(BLE)
监听BLE设备特征值变化
监听BLE设备特征值变化
最后更新:2024/11/13

目录

  • ww.onBLECharacteristicValueChange(callback)
  • 功能描述
  • 参数说明
  • callback: Function
  • 旧版jweixin调用
  • 示例代码
  • ww.onBLECharacteristicValueChange(callback)

    兼容性:企业微信

    功能描述

    监听低功耗蓝牙设备的特征值变化。

    必须先启用 notify 才能接收到设备推送的 notification。

    ww.onBLECharacteristicValueChange(function(event) {
      console.log(event)
    })

    参数说明

    callback: Function

    参数

    event: Object

    属性类型必填说明
    deviceIdstring

    蓝牙设备 ID

    serviceIdstring

    特征值所属服务 uuid

    characteristicIdstring

    特征值 uuid

    valueArrayBuffer

    特征值最新的值

    使用说明

    VConsole 无法打印出 ArrayBuffer 类型数据

    旧版jweixin调用

    示例代码

    // ArrayBuffer转16进度字符串示例
    function ab2hex(buffer) {
      var 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))
    })
    上一篇启用BLE设备特征值订阅
    下一篇概述
      本节内容
    服务端API
    基础
    数据与智能专区
    应用接收专区通知
    连接微信
    客户联系
    办公
    客户端API
    小程序
    基础
    连接微信
    办公
    JS-SDK
    基础
    连接微信
    办公
    更新日志
    联系我们