请问下楼主这个问题解决了吗?连接低功耗蓝牙也会报错
低功耗蓝牙wx.getBLEDeviceServices接口问题- 当前 Bug 的表现(可附上截图) 使用wx.createBLEConnection连接BLE设备后,接着使用wx.getBLEDeviceServices获取服务UUID,获取服务UUID有时候会报错,errCode为:10004(no service),重新调用wx.getBLEDeviceServices接口还是报同样的错误,如果去调用wx.createBLEConnection重新连接设备,会报错,errCode为:-1(already connected) - 预期表现 wx.createBLEConnection连接设备后,wx.getBLEDeviceServices获取服务UUID应该成功 - 复现路径 - 提供一个最简复现 Demo createBLEConnection: function (deviceId){ wx.createBLEConnection({ deviceId: deviceId, success: (res) => { console.log("createBLEConnection success: ", res) this.getBLEDeviceServices(deviceId) }, fail: (res) => { console.error("createBLEConnection fail: ", res) if (res.errCode == -1){ this.getBLEDeviceServices(deviceId) } else { wx.showModal({ title: '提示', content: '连接失败,请稍后重试!', showCancel: false }) } } }) } getBLEDeviceServices: function (deviceId) { wx.getBLEDeviceServices({ deviceId, success: (res) => { for (let i = 0; i < res.services.length; i++) { if (res.services[i].isPrimary) { let serviceId = res.services[i].uuid wx.getBLEDeviceCharacteristics({ deviceId, serviceId, success: (res) => { console.log('getBLEDeviceCharacteristics success: ', res.characteristics) }, fail: (res) => { console.error('getBLEDeviceCharacteristics failed: ', res) } }) return } } }, fail: (res) => { console.error("getBLEDeviceServices failed: ", res) if (res.errCode == 10004){ wx.showLoading({ title: '设备连接出错,自动重连中', }) setTimeout(() => { let _deviceId = deviceId this.createBLEConnection(_deviceId) //this.getBLEDeviceServices(_deviceId) }, 1000) } } }) }
2019-11-11楼主解决了吗?我发现这个问题也是有的手机存在,有的手机不行
蓝牙, 非首次连接的设备无法通过wx.getBLEDeviceServices获取服务?硬件物联网设备,通过蓝牙与小程序连接,serviceUUid与特征值characteristicUUID都是固定的,如果是首次连接的设备,可以通过wx.getBLEDeviceServices获取服务,根据获取的服务获取characteristicUUID,可以跟蓝牙通信,但是非首次连接的设备,调用wx.getBLEDeviceServices,报错10004 no service , 跳过该步骤,直接使用serviceUUid,characteristicUUID通过wx.writeBLECharacteristicValue,也无法通信,报错10004 ,求助 [图片]
2019-11-11