初学小菜鸡
初学小菜鸡
  • 发布:2020-07-20 16:53
  • 更新:2024-07-05 11:56
  • 阅读:1536

【报Bug】蓝牙getBLEDeviceCharacteristics获取属性值时,微信小程序与APP端会有不同值,APP端无法获取设备正确的值

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win7

HBuilderX类型: 正式

HBuilderX版本号: 2.7.14

手机系统: Android

手机系统版本号: Android 10

手机厂商: 小米

手机机型: 小买9

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

getBLEDeviceCharacteristics() {
let deviceId = this.deviceId;
let serviceId = this.serviceId;
let self = this;
return new Promise((resolve, reject) => {
uni.getBLEDeviceCharacteristics({
deviceId,
serviceId,
success: res => {
console.log('获取设备信息',JSON.stringify(res.characteristics))
for (let _obj of res.characteristics) {
// 获取notify
if (_obj.properties.notify) {
self.notifyId = _obj.uuid;
uni.setStorageSync('notifyId', self.notifyId);
}
// 获取writeId
if (_obj.properties.write) {
self.writeId = _obj.uuid;
uni.setStorageSync('writeId', self.writeId);
}
}

                let result = {  
                    'notifyId': self.notifyId,  
                    'writeId': self.writeId  
                };  
                self.showToast(`获取服务中所有特征值OK,${JSON.stringify(result)}`);  
                resolve(result)  
            },  
            fail: err => {  
                self.showToast(`getBLEDeviceCharacteristics` + JSON.stringify(err));  
                reject(err);  
            }  
        })  

    });  
}

预期结果:

[{"uuid":"0000FFF2-0000-1000-8000-00805F9B34FB","properties":{"read":false,"write":true,"notify":false,"indicate":false}},{"uuid":"0000FFF1-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":true,"indicate":false}}]

实际结果:

[{"uuid":"0000FFF2-0000-1000-8000-00805F9B34FB","properties":{"read":false,"write":false,"notify":false,"indicate":false}},{"uuid":"0000FFF1-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":true,"indicate":false}}]

bug描述:

小程序调试蓝牙设备通过getBLEDeviceCharacteristics获取属性:
[{"uuid":"0000FFF2-0000-1000-8000-00805F9B34FB","properties":{"read":false,"write":true,"notify":false,"indicate":false}},{"uuid":"0000FFF1-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":true,"indicate":false}}];

而使用APP调试的结果则是
[{"uuid":"0000FFF2-0000-1000-8000-00805F9B34FB","properties":{"read":false,"write":false,"notify":false,"indicate":false}},{"uuid":"0000FFF1-0000-1000-8000-00805F9B34FB","properties":{"read":true,"write":false,"notify":true,"indicate":false}}]

同一个设备,小程序与APP返回来的write在小程序跟APP会有不同的值,导致APP端无法对设备特征值中写入二进制数据,希望官网能提供解决办法

2020-07-20 16:53 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

有解决吗?

ting_4855

ting_4855

你好 我也遇到了这个问题 android端返回的write与notify都是false;
但是小程序返回的write与notify都是true ,蓝牙我也加权限了 不知道app是什么问题

要回复问题请先登录注册