AndroidBLE--Measuring distance(测量距离)
2016-07-13 18:56
423 查看
iBeacon介绍
iBeacon是苹果在2013年WWDC上推出一项基于蓝牙4.0(Bluetooth LE | BLE | Bluetooth Smart)的精准微定位技术,当你的手持设备靠近一个Beacon基站时,设备就能够感应到Beacon信号,范围可以从几毫米到50米。
Measuring distance(测量距离)
TX power ,用于确定你和beacon之间距离有多近。根据这个值不但可以获得粗略的信息(比如靠近/远离/不在范围内等),也可以获取精确到米的距离,TX power是距离设备1米测得的信号强度值(RSSI- Received Signal Strength Indication,接收到的信号强弱指标)。假如接收到的信号强度减弱了,那么我们可能在远离。只要知道1米距离的RSSI,以及当前的RSSI(我们可以从接收到的信号中一块获取到这些信息),就可计算出当前距离beacon基站的距离
Android 平台
1 Ibeacon扫描SDK库
Android最常用的是android-beacon-library
beacongithub地址
具体使用方法在项目的README.md 描述的比较详细
2 altbeacon内置设备模型以及用于beacon测距的算法中的系数
{ "models": [ { "coefficient1": 0.42093, "coefficient2": 6.9476, "coefficient3": 0.54992, "version":"4.4.2", "build_number":"KOT49H", "model":"Nexus 4", "manufacturer":"LGE" }, { "coefficient1": 0.42093, "coefficient2": 6.9476, "coefficient3": 0.54992, "version":"4.4.2", "build_number":"LPV79", "model":"Nexus 5", "manufacturer":"LGE", "default": true }, { "coefficient1": 0.9401940951, "coefficient2": 6.170094565, "coefficient3": 0.0, "version":"5.0.2", "build_number":"LXG22.67-7.1", "model":"Moto X Pro", "manufacturer":"XT1115", "default": false }, { "coefficient1": 0.1862616782, "coefficient2": 8.235367435, "coefficient3": -0.45324519, "version":"6.0", "build_number":"MPE24.49-18", "model":"XT1092", "manufacturer":"Motorola", "default": false } ] }
3 ALTBeacon中的测距方法
@Override public double calculateDistance(int txPower, double rssi) { if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1. } LogManager.d(TAG, "calculating distance based on mRssi of %s and txPower of %s", rssi, txPower); double ratio = rssi*1.0/txPower; double distance; if (ratio < 1.0) { distance = Math.pow(ratio,10); } else { distance = (mCoefficient1)*Math.pow(ratio,mCoefficient2) + mCoefficient3; } LogManager.d(TAG, "avg mRssi: %s distance: %s", rssi, distance); return distance; }
方法中的公式用到两个值,一个txpower 一个rssi ,用到两个值就可以通过公式求出距离
4 移动端距离计算
如果当前的设备没有在altbeacon内置设备模型列表中,beacon SDK 则选择Nexus 5系数进行距离计算,如下
public static double calculateAccuracy(int txPower, double rssi) { if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1. } double ratio = rssi * 1.0 / txPower; if (ratio < 1.0) { return Math.pow(ratio, 10); } else { double accuracy = (0.42093) * Math.pow(ratio, 6.9476) + 0.54992; return accuracy; } }
相关文章推荐
- Windows系统中使用C#编写蓝牙通信程序的简单实例
- android通过蓝牙接收文件打开时无法自动选择合适的应用程序
- Android开发中编写蓝牙相关功能的核心代码讲解
- Android系统中的蓝牙连接程序编写实例教程
- Android设备间实现蓝牙(Bluetooth)共享上网
- Android提高之蓝牙隐藏API探秘
- Android编程之蓝牙测试实例
- Android提高之蓝牙传感应用实例
- Android Bluetooth蓝牙技术使用流程详解
- Android Bluetooth蓝牙技术初体验
- Android 蓝牙防丢实现(一)
- Win10如何使用蓝牙传输文件?Win10使用蓝牙传输文件的方法
- 蓝牙与红外传输
- 蓝牙-信息时代的黑马
- 玩转Blueteeth Chat蓝牙交友
- SyncML在蓝牙车载免提装置中的应用
- 手机指令大全,需要可以看看
- 蓝牙英文-译文
- ***工具