微信小程序 监听特征值返回成功但是没有真正的监听成功

小程序 文章 2021-01-28 11:21 0 12 全屏看文

微信小程序 监听特征值返回成功但是没有真正的监听成功Wechat Mini Program The monitoring feature value returns successfully but there is no real monitoring success

微信小程序 监听特征值返回成功但是没有真正的监听成功
框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.notifyBLECharacteristicValueChange 微信安卓客户端 8.0.0 2.14.0

这个问题仅在安卓手机上会出现,并且只在特定的芯片中出现。

1、蓝牙连接成功后,获取设备服务成功后,获取设备特征值成功后进行监听蓝牙特征值变化。

wx.notifyBLECharacteristicValueChange({              deviceId:deviceId,              serviceId:serviceId,              characteristicId: NotifyCharactersticUUID,              statetrue,              success:(res2) =>{                   console.log('监听特征值成功',res2)                },              fail:(res2) => {                console.log("notify fail", res2)              },              complete:(res2) =>{                                      wx.onBLECharacteristicValueChange((characteristic) => {                  const data = Array.prototype.slice.call(new Uint8Array(characteristic.value ))                  console.log('设备返回的特征值',data)                  father.onCharacteristicsHandler(data)                })              }            })


2、这个时候可以看到接口返回的是监听特征值成功了

但是这个时候一直没有特征值返回。

3、于是打开另一个软件nRF Connect 连接上这台设备,并在这里监听特征值变化


4、监听成功后,我返回到小程序,可以看到此时立即有特征值返回了

5、可以判断是接口没有真正的监听特征值成功。


Framework type problem type API / component name terminal type wechat version basic library version applet bug wx.notifyBLECharacteristicValueChange Wechat Android client 8.0.0 2.14.0 this problem only appears on Android phones, and only in specific chips. 1. After the Bluetooth connection is successful, the device service is obtained successfully, and the device characteristic value is obtained successfully, then the Bluetooth characteristic value change is monitored. wx.notifyBLECharacteristicValueChange ({               deviceId:deviceId ,               serviceId:serviceId ,              characteristicId: NotifyCharactersticUUID,              state: true,               success:(res2) =>{                    console.log ('monitoring eigenvalue succeeded ', res2)}, fail: (res2) = > { console.log ("notify fail", res2)              },               complete:(res2) =>{                                       wx.onBLECharacteristicValueChange ((characteristic) => {                  const data =  Array.prototype.slice .call(new Uint8Array( characteristic.value  ))                   console.log (' Characteristic value 'returned by the device, data) father.onCharacteristicsHandler (data)})} (2. At this time, we can see that the interface returns the listening eigenvalue successfully, but no eigenvalue has been returned at this time. 3. So open another software NRF connect to connect to this device, and monitor the change of characteristic value here. 4. After the monitoring is successful, I return to the small program, and you can see that the characteristic value is returned immediately. 5. It can be judged that the interface is not monitoring the characteristic value successfully.

回答:

belief:

开启,监听,发送,接受 这样只要向设备发送了数据,就能接受到数据啊


Ain:

我一直把onBLECharacteristicValueChange写在notifyBLECharacteristicValueChange的前面,没有出现过你说的问题,可以试一下能不能解决。

斑马:监听低功耗蓝牙设备的特征值变化事件。必须先启用 notifyBLECharacteristicValueChange 接口才能接收到设备推送的 notification。
斑马:

请问这个bug什么时候会解决?

-EOF-