蓝牙发送指令后不能正常接受通知
发布于 6 年前 作者 pingma 3296 次浏览 来自 问答

为什么我的发送指令成功后 接受不到蓝牙通知响应了    望大神指点下   对蓝牙确实很陌生

10 回复

官方能推出一个蓝牙的demo吗

现在没发现有iOS11不兼容的反馈。

那能具体说下真正有问题的代码逻辑么?

还是一样 这个蓝牙很不好调啊 到底小程序蓝牙能不能用啊

我这边尝试复现你的问题,需要一段时间,稍等。

好的 多谢了

是我项目还没配人正确的域名的问题吗

能成功打印  但这都是第一进去蓝牙自动发过来的数据  我给他发握手指令并不会返回数据  是不是小程序蓝牙不兼容我ios11的微信 我发的握手指令也和他们安卓一样经过分装 应该是没问题的 但就是不返回握手指令过来  我们公司是用这个想做ETC圈存的

可以加下您的qq咨询下详情问题吗

你好,这边怀疑是vConsole的兼容性问题,能否帮忙配合定位下问题呢?

  1. wx.onBLECharacteristicValueChange 里 打印一个固定字符串 console.log('onBLECharacteristicValueChange') ,看是否有进入这个回调中

  2. 可能存在 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
            }
        })
 
    },
回到顶部