问题标签:蓝牙,uniapp
问题描述:
蓝牙写入失败,res.errMsg返回了ok,但硬件没收到数据 ,
'''
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: buffer,
success(res) {
console.log('writeBLECharacteristicValue success', JSON.stringify(res))
},
'''
但硬件测试是可以的,在手机上另外装了个蓝牙助手,发送是成功的
我获得的:
- deviceId
- serviceId
- characteristicId
是否理解错了,characteristicId是可写,serviceId是第一个并且isPrimary:true
蓝牙搜索
{"deviceId":"90:9A:77:2C:68:F5","name":"HC-08","RSSI":-63,"localName":"HC-08","advertisServiceUUIDs":["0000FFF0-0000-1000-8000-00805F9B34FB"],"advertisData":{}}
获得:
deviceId:90:9A:77:2C:68:F5
获取蓝牙服务:
{"services":[{"uuid":"00001800-0000-1000-8000-00805F9B34FB","isPrimary":true},{"uuid":"00001801-0000-1000-8000-00805F9B34FB","isPrimary":true},{"uuid":"0000180A-0000-1000-8000-00805F9B34FB","isPrimary":true},{"uuid":"0000FFF0-0000-1000-8000-00805F9B34FB","isPrimary":true},{"uuid":"0000FFE0-0000-1000-8000-00805F9B34FB","isPrimary":true}],"errMsg":"getBLEDeviceServices:ok","errCode":0}
获得
serviceId:00001800-0000-1000-8000-00805F9B34FB
获得特征值:{"characteristics":[{"uuid":"00002A00-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":false,"indicate":false}},{"uuid":"00002A01-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":false,"indicate":false}},{"uuid":"00002A02-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":true,"notify":false,"indicate":false}},{"uuid":"00002A03-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":true,"notify":false,"indicate":false}},{"uuid":"00002A04-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":false,"indicate":false}}],"errMsg":"getBLEDeviceCharacteristics:ok"}
获得
characteristicId:00002A02-0000-1000-8000-00805F9B34FB
(上述代码略)
然后写蓝牙数据:
'''
const buffer = new ArrayBuffer(1)
const dataView = new DataView(buffer)
dataView.setUint8(0, 0)
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: buffer,
success(res) {
console.log('writeBLECharacteristicValue success', JSON.stringify(res))
},
fail: function(res) {
console.log("数据发送失败:" + JSON.stringify(res))
},
})
'''
返回是发送成功的,但硬件没有收到,我有什么做错了,感谢任何回答