sendtoequ: function (e) {
var that = this
console.log(this.data.services)
console.log(“发送消息到:deviceId” + that.data.connectedDeviceId);
console.log(“serviceId:” + that.data.services[0].uuid);
console.log(“characteristicId:” + that.data.characteristicId);
//这里是核心,自己编码协议
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 6)
//这里是核心,自己编码协议
wx.writeBLECharacteristicValue({
// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
deviceId: that.data.connectedDeviceId,
// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
serviceId: that.data.services[0].uuid,
// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
characteristicId: that.data.characteristicId,
// 这里的value是ArrayBuffer类型
value: buffer,
success: function (res) {
console.log(res)
console.log(‘writeBLECharacteristicValue success’, res.errMsg)
}
})
}
这段是给蓝牙设备发了一个字节