z***@qq.com
z***@qq.com
  • 发布:2019-01-25 18:36
  • 更新:2019-06-12 11:06
  • 阅读:2146

【报Bug】uni-app 蓝牙模块 BUG

分类:nvue

详细问题描述(DCloud产品不会有明显的bug,所以你遇到的问题大都是在特定环境下才能重现的问题,请仔细描述你的环境和重现方式,否则DCloud很难排查解决你的问题)
[内容]

uni.getBLEDeviceServices({  
    // 这里的 deviceId 需要在上面的 getBluetoothDevices中获取  
    deviceId: that.blue_data.device_id,  
    success: function(res) {  
        that.log("getBLEDeviceServices success", res)  
        /*** 延迟1500毫秒,根据服务获取特征  */  
        setTimeout(function() {  
            uni.getBLEDeviceCharacteristics({  
                // 这里的 deviceId 需要在上面的 getBluetoothDevices  
                deviceId: that.blue_data.device_id,  
                // 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取  
                serviceId: that.blue_data.serviceId,  
                success: function(res) {  
                    that.log("getBLEDeviceCharacteristics characteristics success", res.characteristics)  
                    // forEach方法遍历  
                    res.characteristics.forEach(function(obj) {  
                        if (obj.uuid.indexOf("ffb1") != -1 || obj.uuid.indexOf("FFB1") != -1) {  
                            that.blue_data.cd20 = obj.uuid  
                            if (that.blue_data.deviceSystemNumber == 0) {  
                                that.writeToBLE_userInfo();  
                            }  
                        }  
                        if (obj.uuid.indexOf("ffb2") != -1 || obj.uuid.indexOf("FFB2") != -1) {  
                            that.blue_data.cd01 = obj.uuid.toUpperCase()  
                        }  
                    });  

                    /*** 顺序开发设备特征notifiy */  
                    that.log('===顺序开发设备特征===');  
                    that.log('deviceId', that.blue_data.device_id);  
                    that.log('serviceId', that.blue_data.serviceId);  
                    that.log('characteristicId', that.blue_data.cd01);  
                    that.log('===notifyBLECharacteristicValueChange start===');  
                    uni.notifyBLECharacteristicValueChange({  
                        state: true,  
                        deviceId: that.blue_data.device_id,  
                        serviceId: that.blue_data.serviceId,  
                        characteristicId: that.blue_data.cd01,  
                        success: function(res) {  
                            that.log('顺序开发设备特征notifiy notifyBLECharacteristicValueChange success:', res);  
                            if (that.blue_data.deviceSystemNumber == 1) {  
                                that.writeToBLE_userInfo();  
                            }  
                        },  
                        fail: function(res) {  
                            that.log('顺序开发设备特征notifiy notifyBLECharacteristicValueChange fail:', res);  
                        }  
                    })  
                    that.log('===notifyBLECharacteristicValueChange end===');  
                },  
                fail: function(res) {  
                    that.log('获取设备特征值 getBLEDeviceCharacteristics fail', res);  
                    that.link_device();  
                }  
            })  

            /** * 回调获取 设备发过来的数据 */  
            uni.onBLECharacteristicValueChange((characteristic) => {  
                /*** 监听ffb2中的结果 ***/  
                if (characteristic.characteristicId.indexOf("ffb2") != -1 || characteristic.characteristicId.indexOf(  
                        "FFB2") != -1) {  
                    const result = characteristic.value  
                    const hex = Tea.buf2hex(result)  
                    // 解析参数调用  
                    that.handledata(result)  
                    var lastValue = hex  
                    // 显示蓝牙返回的16进制:  
                    that.blue_data.resultBLE = lastValue  
                }  
                if (characteristic.characteristicId.indexOf("1801") != -1) {  
                    const result = characteristic.value  
                    const hex = Tea.buf2hex(result)  
                    // 解析参数调用  
                    that.handledata(result)  
                    var lastValue = hex  
                    // 显示蓝牙返回的16进制:  
                    that.blue_data.resultBLE = lastValue  
                }  
            })  

        }, 500);  

        /*** 监听设备的连接状态: 就断开时会走这个方法   ***/  
        uni.onBLEConnectionStateChange(function(res) {  
            if (res.connected == false) {  
                that.log("连接断开")  
                that.link_device();  
            }  
        });  
    },  
    fail: function(res) {  
        that.log("getBLEDeviceServices fail", res)  
        that.log('deviceId', that.blue_data.device_id);  
        //that.link_device();  
    }  
});  

这段代码无效
getBLEDeviceServices 这个无法获取服务ID

重现步骤
[步骤]
[结果]
[期望]

期望和小程序一样,小程序是可以使用的

[如果语言难以表述清晰,可以拍一个视频或截图,有图有真相]

IDE运行环境说明
[HBuilder 或 HBuilderX]
最新
[IDE版本号]
最新
[windows版本号]
win10
[mac版本号]

App运行环境说明
[Android版本号]
8.0.1
[iOS版本号]
[手机型号]
华为8X
[模拟器型号]

附件
[IDE问题请提供HBuilderX运行日志。菜单帮助-查看运行日志,点右键打开文件所在目录,将log文件压缩成zip包上传]
[App问题请提供可重现问题的代码片段,你补充的细一点,问题就解决的快一点]
[安装包]

联系方式
[QQ]
286277686

2019-01-25 18:36 负责人:无 分享
已邀请:
DCloud_Android_zl

DCloud_Android_zl

麻烦重新描述一下,什么情况下会触发这个问题。

  • 了了_

    安卓手机华为p10每次测试都是空的

    2019-03-11 11:42

  • DCloud_Android_zl

    @744989745@qq.com:app是否获得了蓝牙权限和定位权限。

    2019-03-11 15:16

2***@qq.com

2***@qq.com

不知楼主当时怎么解决的,我现在的也是低功耗蓝牙,在获取设备的services列表出问题,获取的为空。

  • 3***@qq.com

    你这边解决了么?是怎么解决的呢?

    2019-06-11 18:06

2hai

2hai

getConnectedBluetoothDevices,我这边是这个方法没法获得连接的蓝牙列表

该问题目前已经被锁定, 无法添加新回复