微信小程序连接蓝牙设备,向设备发送cmd_read指令获取返回数据示例代码
时间: 2023-04-01 07:03:41 浏览: 84
以下是示例代码:
wx.onBluetoothDeviceFound(function(devices) {
var deviceId = devices[].deviceId
wx.createBLEConnection({
deviceId: deviceId,
success: function(res) {
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: '000FFF-000-100-800-00805F9B34FB',
characteristicId: '000FFF1-000-100-800-00805F9B34FB',
value: ArrayBuffer.from([x01, x02, x03, x04]),
success: function(res) {
wx.readBLECharacteristicValue({
deviceId: deviceId,
serviceId: '000FFF-000-100-800-00805F9B34FB',
characteristicId: '000FFF1-000-100-800-00805F9B34FB',
success: function(res) {
console.log('readBLECharacteristicValue:', res)
}
})
}
})
}
})
})
阅读全文