小程序蓝牙的写入数据问题 求助~!
先打开
wx.notifyBLECharacteristicValueChange(OBJECT)
这个功能 然后再写入
wx.writeBLECharacteristicValue(OBJECT)
就会写入失败吗?
我试过先写入 再打开notify就可以写入成功 可是这样的话 第一写入时的特征值变化是监听到了吗
wx.onBLECharacteristicValueChange(function(characteristic) {
console.log('characteristic value changed:', characteristic)
})
// 向蓝牙设备发送一个0x00的16进制数据
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 0)
wx.writeBLECharacteristicValue({ // 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
deviceId: deviceId, // 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
serviceId: serviceId, // 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
characteristicId: characteristicId, // 这里的value是ArrayBuffer类型
value: buffer,
success: function (res) { console.log('writeBLECharacteristicValue success', res.errMsg)
}
})
还有一个问题就是 小程序的蓝牙接口是不会自动跟蓝牙设备认证的吗?还是要自己手动写一个跟设备握手的过程?
谢谢~
