q***@gmail.com
q***@gmail.com
  • 发布:2019-03-02 18:02
  • 更新:2019-09-12 11:31
  • 阅读:3937

实时读取已连接的蓝牙设备的RSSI

分类:HTML5+

我在使用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;  
                         }  
                  }  
           });  

2019-03-02 18:02 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com

你好 请问怎么获取已经连接的蓝牙设备 我用getConnectedBluetoothDevices都获取不到

  • j***@163.com

    老哥解决了吗,我也遇到相同的问题了


    2019-09-26 14:57

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