小程序
小游戏
企业微信
微信支付
扫描小程序码分享
我现在这边的情况是这样的,写了小程序蓝牙的demo,用的ios测试,但是wx.onBLECharacteristicValueChange这个无法回调,我用的特征值是支持write+notify的,notify是成功开启了,蓝牙设备那边也是观察到写入特征值成功,但是不知道为什么就是不回调这个特征值变化事件,请问有人知道怎么解决吗?
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
调这个,wx.notifyBLECharacteristicValueChange,可能会fail 10008,但其实还是能收到数据
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
openBluetoothAdapter: function () { wx.openBluetoothAdapter({ success: res => { console.log(res); } }) }, connect: function() { wx.startBluetoothDevicesDiscovery({ services: ['0000FEE1-0000-1000-8000-00805F9B34FB'], allowDuplicatesKey: true, success: res => { console.log(JSON.stringify(res)); wx.getBluetoothDevices({ success: res => { console.log('getBluetoothDevices:' + JSON.stringify(res)); if(res.devices.length > 0) { this.setData({ deviceId: res.devices[0].deviceId }) wx.createBLEConnection({ deviceId: res.devices[0].deviceId, complete: res => { console.log('createBLEConnection:' + JSON.stringify(res)); } }) } } }) } }); }, notify: function() { wx.getBLEDeviceServices({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', complete: function (res) { console.log('getBLEDeviceServices:' + JSON.stringify(res)); wx.getBLEDeviceCharacteristics({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', complete: function (res) { console.log('getBLEDeviceCharacteristics:' + JSON.stringify(res)); wx.notifyBLECharacteristicValueChange({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', characteristicId: '00001003-0000-1000-8000-00805F9B34FB', state: true, complete: res => { console.log(JSON.stringify(res)); } }) wx.onBLECharacteristicValueChange((res) => { console.log('onBLECharacteristicValueChange:' + JSON.stringify(res)); }); } }) } }) }, write: function(){ let buffer = new ArrayBuffer(1) let dataView = new DataView(buffer) dataView.setUint8(0, 0) wx.writeBLECharacteristicValue({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', characteristicId: '00001003-0000-1000-8000-00805F9B34FB', value: buffer, complete: function (res) { console.log('writeBLECharacteristicValue:' + JSON.stringify(res)); // wx.readBLECharacteristicValue({ // deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', // serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', // characteristicId: '00001003-0000-1000-8000-00805F9B34FB', // success: function(res) { // console.log('readBLECharacteristicValue:' + JSON.stringify(res)); // }, // }) }, }) },
onBLECharacteristicValueChange 没有回调
手机 iPhone 11 Pro, iOS 13.3
微信 7.0.12
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
调这个,wx.notifyBLECharacteristicValueChange,可能会fail 10008,但其实还是能收到数据
openBluetoothAdapter: function () { wx.openBluetoothAdapter({ success: res => { console.log(res); } }) }, connect: function() { wx.startBluetoothDevicesDiscovery({ services: ['0000FEE1-0000-1000-8000-00805F9B34FB'], allowDuplicatesKey: true, success: res => { console.log(JSON.stringify(res)); wx.getBluetoothDevices({ success: res => { console.log('getBluetoothDevices:' + JSON.stringify(res)); if(res.devices.length > 0) { this.setData({ deviceId: res.devices[0].deviceId }) wx.createBLEConnection({ deviceId: res.devices[0].deviceId, complete: res => { console.log('createBLEConnection:' + JSON.stringify(res)); } }) } } }) } }); }, notify: function() { wx.getBLEDeviceServices({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', complete: function (res) { console.log('getBLEDeviceServices:' + JSON.stringify(res)); wx.getBLEDeviceCharacteristics({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', complete: function (res) { console.log('getBLEDeviceCharacteristics:' + JSON.stringify(res)); wx.notifyBLECharacteristicValueChange({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', characteristicId: '00001003-0000-1000-8000-00805F9B34FB', state: true, complete: res => { console.log(JSON.stringify(res)); } }) wx.onBLECharacteristicValueChange((res) => { console.log('onBLECharacteristicValueChange:' + JSON.stringify(res)); }); } }) } }) }, write: function(){ let buffer = new ArrayBuffer(1) let dataView = new DataView(buffer) dataView.setUint8(0, 0) wx.writeBLECharacteristicValue({ deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', characteristicId: '00001003-0000-1000-8000-00805F9B34FB', value: buffer, complete: function (res) { console.log('writeBLECharacteristicValue:' + JSON.stringify(res)); // wx.readBLECharacteristicValue({ // deviceId: '48ADF6C5-261F-D9B0-BD6C-91FCF8B57737', // serviceId: '0000FEE1-0000-1000-8000-00805F9B34FB', // characteristicId: '00001003-0000-1000-8000-00805F9B34FB', // success: function(res) { // console.log('readBLECharacteristicValue:' + JSON.stringify(res)); // }, // }) }, }) },
onBLECharacteristicValueChange 没有回调
手机 iPhone 11 Pro, iOS 13.3
微信 7.0.12
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)