微信小程序 > 微信公开课 > 小程序wxnotifyBLECharacteristicValueChanged
微信小程序,微信公开课,小程序wxnotifyBLECharacteristicValueChanged

小程序wxnotifyBLECharacteristicValueChanged

2019-04-03 15:13:30

如何看待微信公开课小程序热门讨论「小程序wxnotifyBLECharacteristicValueChanged」
摘要:小程序wxnotifyBLECharacteristicValueChanged
展开:wx.notifyBLECharacteristicValueChanged设置后没有效果,求大神指点!现象:蓝牙连接成功后,设备上传消息给小程序,小程序无法自动读取并提示,需要手动执行wx.readBLECharacteristicValue才会在wx.onBLECharacteristicValueChange方法中获得消息。手动执行存在每次点击都会读取Characteristic中的值,无法判断这个值是否已读。设置步骤如下:onLoad:function(){wx.onBLECharacteristicValueChange(function(res){//获得消息解码并输出console.log(value:,characteristic+res.characteristicId+aschanged,nowis+res.value);//console.log(value:,value+res.value[0]++res.value[1]);letbufferres.valueletdataViewnewDataView(buffer)console.log(value:,dataView.getUint8(0))})}updateBTDevs:function(dev){console.log(JSON.stringify(dev));varthatthis;if(this.btdevshashnulldev[name]Xinda){this.btdevshashdev;wx.createBLEConnection({//连接蓝牙设备deviceId:that.btdevshash[deviceId],success:function(res){console.log(res);setTimeout(function(){wx.notifyBLECharacteristicValueChanged({//连接后设置监听deviceId:that.btdevshash[deviceId],serviceId:0000180f00001000800000805f9b34fb,characteristicId:00002a1900001000800000805f9b34fb,state:true,success:function(res){console.log(bind:,res);},fail:function(res){console.log(bindfailed,res)}})}.bind(this),3000)}})}},设置过程中,此Characteristic的属性notify可以修改,并成功修改为true,但是notify功能不工作。于是增加按钮执行readBLECharacteristicValue做测试,每次点击按钮,可以在onBLECharacteristicValueChange函数中获得最新值(读取后再次读取还是这个值)代码如下:bindHelp:function(){wx.readBLECharacteristicValue({deviceId:this.btdevshash[deviceId],serviceId:0000180f00001000800000805f9b34fb,characteristicId:00002a1900001000800000805f9b34fb,success:function(res){console.log(readBLECharacteristicValue:,res)}})},
标签:小程序
微信小程序,微信公开课,小程序wxnotifyBLECharacteristicValueChanged

「小程序wxnotifyBLECharacteristicValueChanged」热门讨论订阅

方法1:微信扫描微信公开课小程序码即可订阅热门讨论「小程序wxnotifyBLECharacteristicValueChanged」

方法2:微信搜索微信公开课小程序名称进入,即可订阅热门讨论「小程序wxnotifyBLECharacteristicValueChanged」

方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热门讨论「小程序wxnotifyBLECharacteristicValueChanged」

微信公开课小程序热门讨论「小程序wxnotifyBLECharacteristicValueChanged」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。

微信公开课热门讨论「小程序wxnotifyBLECharacteristicValueChanged」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。