https://developers.weixin.qq.com/miniprogram/dev/framework/device/bluetooth.html
开发微信蓝牙BLE通讯小程序,基于微信小程序蓝牙官方开发文档中提供的“示例代码”,载入开发者工具发送数据测试无响应,将原有的示例代码中“serviceId: this._deviceId”更改为“serviceId: this._serviceId”,则可发送随机数据。官方微信小程序蓝牙示例代码片段如下:
writeBLECharacteristicValue() {
// 向蓝牙设备发送一个0x00的16进制数据
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, Math.random() * 255 | 0)
wx.writeBLECharacteristicValue({
deviceId: this._deviceId,
serviceId: this._deviceId,
characteristicId: this._characteristicId,
value: buffer,
})
},
感谢反馈