已解决 是硬件方面的问题
startBluetoothDevicesDiscovery传入services之后收不到回调?startBluetoothDevicesDiscovery传入services之后onBluetoothDeviceFound收不到回调 不传services的话onBluetoothDeviceFound有回调 并且返回值的servicesData里有数据 且跟我传的services是一样的有没有大佬知道是什么原因啊 求回复!!![图片]
2023-10-30你好 请问解决了吗 ?
低功耗蓝牙onBLECharacteristicValueChange未触发回调?场景: 流程一: 正常初始化蓝牙,询问适配器状态,搜索蓝牙列表,手动点击列表中蓝牙设备连接(缓存设备id),......(获取服务id,特征值id等操作),跳转蓝牙状态面板,notify-write,onBLECharacteristicValueChange监听返回数据,正常。 结果图: [图片] 流程二: 重新进入小程序(右上角三个点-重新进入小程序),正常初始化蓝牙,询问适配器状态,搜索蓝牙列表,通过缓存设备id自动连接蓝牙设备,......(获取服务id,特征值id等操作),跳转蓝牙状态面板,notify-write,onBLECharacteristicValueChange未进入回调。notify和write返回 [图片] 代码方面: 1、缓存设备id [图片] 2、自动链接 [图片] 3、notify [图片]
2022-12-28楼主解决了吗 我的也是这样
低功耗蓝牙 writeBLECharacteristicValue接口 无任何回调?基础库版本:2.24.1 微信版本:8.0.22 手机型号:MI 9 安卓版本:9 描述: writeBLECharacteristicValue 写入接口调用后无任何回调。success,fail,complete 都没有回调。onBLECharacteristicValueChange 也没有触发 但数据似乎写入进去了。通过 readBLECharacteristicValue 读取到的 特征value 为我写入进去的值。虽然我不是要我写入的值,而是要通过写入 让设备反馈给我数据。 readBLECharacteristicValue 有回调 success ,fail,complete,onBLECharacteristicValueChange 都能触发。 真机调试截图: [图片][图片] 部分代码: getBLEDeviceServices(deviceId) { wx.getBLEDeviceServices({ deviceId, success: (res) => { for (let i = 0; i < res.services.length; i++) { if (res.services[i].isPrimary) { console.log(res.services[i]) } } // this.getBLEDeviceCharacteristics(deviceId, res.services[4].uuid) this.getBLEDeviceCharacteristics(deviceId, res.services[2].uuid) this.getBLEDeviceCharacteristics(deviceId, res.services[3].uuid) this.getBLEDeviceCharacteristics(deviceId, res.services[4].uuid) this.getBLEDeviceCharacteristics(deviceId, res.services[5].uuid) } }) }, getBLEDeviceCharacteristics(deviceId, serviceId) { wx.getBLEDeviceCharacteristics({ deviceId, serviceId, success: (res) => { console.log('getBLEDeviceCharacteristics success', res.characteristics) for (let i = 0; i < res.characteristics.length; i++) { let item = res.characteristics[i] console.log(item) if (item.properties.read) { wx.readBLECharacteristicValue({ deviceId, serviceId, characteristicId: item.uuid, success: (res) => { console.log(res) console.log('读取成功') } }) } if (item.properties.write) { this.setData({ canWrite: true }) this._deviceId = deviceId this._serviceId = serviceId this._characteristicId = item.uuid let data = 0 if (serviceId === '0000FFF0-0000-1000-8000-00805F9B34FB') { data = 0xff } if (serviceId === '0000FFE0-0000-1000-8000-00805F9B34FB') { data = 0x11 } if (serviceId === '0000FFB1-0000-1000-8000-00805F9B34FB') { data = 0x14 } this.writeBLECharacteristicValue(data) } if (item.properties.notify || item.properties.indicate) { wx.notifyBLECharacteristicValueChange({ deviceId, serviceId, characteristicId: item.uuid, state: true, }) } } }, fail(res) { console.error('getBLEDeviceCharacteristics', res) } }) // 操作之前先监听,保证第一时间获取数据 wx.onBLECharacteristicValueChange((characteristic) => { console.log('接受') console.log(characteristic) const idx = inArray(this.data.chs, 'uuid', characteristic.characteristicId) const data = {} if (idx === -1) { data[`chs[${this.data.chs.length}]`] = { uuid: characteristic.characteristicId, value: ab2hex(characteristic.value) } } else { data[`chs[${idx}]`] = { uuid: characteristic.characteristicId, value: ab2hex(characteristic.value) } } // data[`chs[${this.data.chs.length}]`] = { // uuid: characteristic.characteristicId, // value: ab2hex(characteristic.value) // } this.setData(data) }) }, writeBLECharacteristicValue(data) { // 向蓝牙设备发送一个0x00的16进制数据 let buffer = new ArrayBuffer(1) let dataView = new DataView(buffer) data = data || 0x10 dataView.setUint8(0, data) console.log('写入数据') console.log(buffer) wx.writeBLECharacteristicValue({ deviceId: this._deviceId, serviceId: this._serviceId, characteristicId: this._characteristicId, writeType: 'write', value: buffer, success: () => { console.log('成功!') }, fail: () => { console.log('失败!') }, complete: () => { console.log('结束!') } }) },
2022-12-19