Measuring distance(测量距离)
Android 平台
1 Ibeacon扫描SDK库
Android最常用的是android-beacon-library
具体使用方法在项目的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;
}
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;
}
4 移动端距离计算
如果当前的设备没有在altbeacon内置设备模型列表中,beacon SDK 则选择Nexus 5系数进行距离计算,如下
public static double calculateAccuracy(int txPower, double rssi) {
if (rssi == 0) { return -1.0;
}
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;
}
}