微信小程序连接蓝牙设备,向设备发送cmd_read指令获取返回数据示例代码
时间: 2023-03-31 08:05:01 浏览: 173
微信小程序 蓝牙的实现实例代码
以下是示例代码:
wx.getBluetoothAdapterState({
success: function(res) {
if (res.available) {
wx.startBluetoothDevicesDiscovery({
success: function(res) {
wx.onBluetoothDeviceFound(function(devices) {
if (devices[].name == '设备名称') {
wx.createBLEConnection({
deviceId: devices[].deviceId,
success: function(res) {
wx.getBLEDeviceServices({
deviceId: devices[].deviceId,
success: function(res) {
wx.getBLEDeviceCharacteristics({
deviceId: devices[].deviceId,
serviceId: res.services[].uuid,
success: function(res) {
wx.readBLECharacteristicValue({
deviceId: devices[].deviceId,
serviceId: res.characteristics[].serviceId,
characteristicId: res.characteristics[].uuid,
success: function(res) {
console.log('读取到的数据为:' + res.value)
}
})
}
})
}
})
}
})
}
})
}
})
}
}
})
阅读全文