蓝牙读数据
readBLECharacteristicValue: function (deviceId, serviceId, characteristicId, callback) {
wx.onBLECharacteristicValueChange(function (characteristic) {
console.log(‘characteristic value comed:’);
let buffer = characteristic.value;
let dataView = new DataView(buffer);
console.log(“接收字节长度:” + dataView.byteLength);
console.log(dataView.getUint8(0));
console.log(dataView.getUint8(1));
callback(dataView);
});
wx.readBLECharacteristicValue({
// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
deviceId: deviceId,
// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
serviceId: serviceId,
// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
characteristicId: characteristicId,
success: function (res) {
console.log(‘readBLECharacteristicValue:’, res)
}
})
}
设备一直在广播数据 ,这里的readBLECharacteristicValue 要轮询么 譬如1s钟调用一次 ,还是不需要轮询,调用一次后,只要有数据就会进wx.onBLECharacteristicValueChange
wx.onBLECharacteristicValueChange 这个函数的回调函数参数characteristic.value 该如何显示
