10 回复
能成功打印 但这都是第一进去蓝牙自动发过来的数据 我给他发握手指令并不会返回数据 是不是小程序蓝牙不兼容我ios11的微信 我发的握手指令也和他们安卓一样经过分装 应该是没问题的 但就是不返回握手指令过来 我们公司是用这个想做ETC圈存的
你好,这边怀疑是vConsole的兼容性问题,能否帮忙配合定位下问题呢?
在 wx.onBLECharacteristicValueChange 里 打印一个固定字符串 console.log('onBLECharacteristicValueChange') ,看是否有进入这个回调中
可能存在 console.log 无法打印出你的变量 str 的可能,有办法每次进入 wx.onBLECharacteristicValueChange 将收到的值打印在页面上么?
onLoad: function (opt) { var that = this ; console.log( "onLoad" ); console.log( '丽江deviceId=' + opt.deviceId); console.log( 'name=' + opt.name); that.setData({ deviceId: opt.deviceId }); /** * 监听设备的连接状态 */ wx.onBLEConnectionStateChanged( function (res) { wx.showModal({ title: '2' , content: '' + res.connected, }) console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`) }) /** * 连接设备 */ wx.createBLEConnection({ deviceId: that.data.deviceId, success: function (res) { // success console.log(res); wx.showModal({ content: '连接' + that.data.deviceId, }) console.log( '丽江2' + that.data.deviceId) //获取服务 wx.getBLEDeviceServices({ deviceId: that.data.deviceId, success: function (res){ console.log( '李建' + res.services[0].uuid) //获取特征 wx.getBLEDeviceCharacteristics({ deviceId: that.data.deviceId, serviceId: '0000FEE7-0000-1000-8000-00805F9B34FB' , success: function (){ //接受信息 wx.notifyBLECharacteristicValueChange({ state: true , deviceId: that.data.deviceId, serviceId: '0000FEE7-0000-1000-8000-00805F9B34FB' , characteristicId: '0000FEC8-0000-1000-8000-00805F9B34FB' , success: function (res) { console.log( 'notifyBLECharacteristicValueChange success' , res.errMsg) }, fail: function (res) { wx.showModal({ content: 'aa' + res.errMsg, }) } }); //notify成功后的回调 wx.onBLECharacteristicValueChange( function (characteristic) { let valll = characteristic.value let aa = new Uint8Array(valll) let str = "" ; for (let i = 0; i < aa.length; i++) { let temp = aa[i].toString(16) temp = temp.length == 1 ? "0" + temp : temp; str += temp } console.log( 'faguolai:' +str) that.setData({ result: str }) }) } }) } }) }, fail: function (res) { // fail }, complete: function (res) { // complete } }) }, |