我在使用MUI开发BLE智能硬件app的时候,需要在设备已经连接后周期性去读取rssi值。我首先尝试了调用getBluetoothDevices()方法,但是读取的RSSI没有变化,我推测这个RSSI是扫描发现设备时记录的,并没有再更新。

plus.bluetooth.getBluetoothDevices({

success:function(e){

var devices = e.devices;

for(var i in devices){

if (devices[i].name == deviceName){

rssi_value = devices[i].RSSI;

console.log("rssi_value = " + rssi_value);

}

}

},

fail:function(e){

console.log('connected devices failed: '+JSON.stringify(e));

}

});

接下来我又尝试使用getConnectedBluetoothDevices()方法,遗憾的是,它返回的devices中只包含name和deviceId两个属性(官方介绍里面确实也是这样说的),所以依然没法读到RSSI。

在此求助大家,希望大牛和官方不吝赐教如何解决这个问题,先行拜谢了。

PS: 我目前只能断开蓝牙连接,在startBluetoothDevicesDiscovery办法中定义allowDuplicatesKey为true,重新开始扫描蓝牙设备,但是不能连接设备,在onBluetoothDeviceFound()方法中去读取刷新的RSSI值。

plus.bluetooth.startBluetoothDevicesDiscovery({

allowDuplicatesKey: true,

success: function(e){

outSet('开始搜索成功!');

},

failed: function(e){

outSet('开始搜索失败! '+JSON.stringify(e));

}

});

plus.bluetooth.onBluetoothDeviceFound(function(e){

var devices = e.devices;

for(var i in devices){

if (devices[i].name == deviceName){

var device = devices[i];

rssi_value = device.RSSI;

}

}

});

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐