b7ur
b7ur
  • 发布:2019-10-13 23:19
  • 更新:2020-05-29 09:45
  • 阅读:2114

蓝牙返回ok,但硬件没收到,serviceId是如何取的

分类:uni-app

问题标签:蓝牙,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))
},

    })  

'''
返回是发送成功的,但硬件没有收到,我有什么做错了,感谢任何回答

2019-10-13 23:19 负责人:无 分享
已邀请:
b7ur

b7ur (作者) - 第7罗汉

蓝牙characteristicId 是不是要求: notify、read、write三者同时为true.我试试

b7ur

b7ur (作者) - 第7罗汉

notify,改变到真,也无法收到,再次查询属性值,notify:false,如何设备

浮休

浮休 - 浮休

楼主解决了吗?我也是这样,返回ok,但是设备没响应...

该问题目前已经被锁定, 无法添加新回复