如何获得一个蓝牙低功耗设备的RSSI值? [英] how to get the rssi value for a bluetooth low energy device ?

查看:1687
本文介绍了如何获得一个蓝牙低功耗设备的RSSI值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新与Android编程并试图获得RSSI值形成距离的BLE装置measurements.i可以扫描并获得该设备的名称和MAC地址,但我试过codeS得到RSSI但不能得到有用的结果,也是我用的Andr​​oid开发者网站上的样品。
有人可以给我正确的code这样做?

I am new with android programming and trying to get rssi value form a BLE device for distance measurements.i can scan and get the name and mac address of the device but i've tried codes to get the rssi but can't get useful result,also i use the sample on the android developer site. can someone give me the right code to do so??

推荐答案

有关this.There两种解决方案是不同的方法可以有4.0和5.0的设备搜索/扫描BLE设备。你没有提到你使用的是哪一个,因此下面将双方的解决方案。

Two solution for this.There is different approach one can have for 4.0 and 5.0 devices to search/scan BLE devices. You did not mentioned which one you are using, hence adding both the solution below.

1),为Android 4.4 +到5.0,你必须通过 BluetoothAdapter的 startLEScan 方法,启动LE扫描哪些给你下面RSSI值的回调。参见方法的签名。

1) for Android 4.4 + till 5.0, you have to start LE scanning via BluetoothAdapter's startLEScan method, which gives you below callback with RSSI value. see signature of method.

onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)

//上面的第二个参数是RSSI值。

// second param above is RSSI value.

2)对于Android 5.0以上版本的设备,你必须开始由BluetoothLeScanner类的startScan法扫描,如下面

2) For android 5.0+ devices you have to start scanning by BluetoothLeScanner class's startScan method, like below

getBluetoothLeScanner().startScan

有回调onScanResult通知新的扫描设备,可以使用下面code得到RSSI。

which has callback onScanResult to notify for new scanned device, you can use below code to get rssi.

public void onScanResult(int callbackType, ScanResult result) {
final int rssi = result.getRssi(); //RSSI value

这篇关于如何获得一个蓝牙低功耗设备的RSSI值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆