【发布时间】:2015-05-08 08:15:43
【问题描述】:
我正在开发一个应用程序,该应用程序根据信标的范围(例如位置
问题
05-08 10:09:48.379 21495-22283 I/RangingService? RSSI: 127 Distance: 2533.712149492241 meters
05-08 10:09:49.500 21495-22284 I/RangingService? RSSI: -38 Distance: 0.07068384635393776 meters
05-08 10:09:50.662 21495-22301 I/RangingService? RSSI: 127 Distance: 0.07068384635393776 meters
05-08 10:09:51.795 21495-22302 I/RangingService? RSSI: 127 Distance: 2533.712149492241 meters
05-08 10:09:52.946 21495-22318 I/RangingService? RSSI: -34 Distance: 0.10971085339590038 meters
05-08 10:09:54.074 21495-22327 I/RangingService? RSSI: 127 Distance: 0.10971085339590038 meters
05-08 10:09:55.375 21495-22404 I/RangingService? RSSI: 127 Distance: 2533.712149492241 meters
05-08 10:09:56.499 21495-22488 I/RangingService? RSSI: -36 Distance: 0.08827424889527898 meters
05-08 10:09:57.637 21495-22492 I/RangingService? RSSI: -36 Distance: 0.008486821580451052 meters
05-08 10:09:58.771 21495-22493 I/RangingService? RSSI: 127 Distance: 0.08827424889527898 meters
05-08 10:09:59.902 21495-22509 I/RangingService? RSSI: 127 Distance: 2533.712149492241 meters
如果您查看距离,它会在 rssi 为 127 之后或之后的每次计算中随机出现峰值。我不明白为什么 rssi 会如此频繁地随机变为 127。有什么想法吗?
解决方法
int rssi2use = beacon.getRssi();
if (rssi2use == 127) {
Log.i(TAG, "Using last Rssi " + lastRssi + " instead of 127");
rssi2use = lastRssi;
} else {
lastRssi = beacon.getRssi();
}
MyBeacon.java 简化距离计算以清除 rssis 的平均值
public class MyBeacon extends Beacon {
private static final String TAG = MyBeacon.class.getSimpleName();
private final Beacon beacon;
private final int rssi2use;
public MyBeacon(final Beacon beacon, int rssi2use) {
this.beacon = beacon;
this.rssi2use = rssi2use;
}
@Override
public double getDistance() {
return mDistance = calculateDistance(beacon.getTxPower(), rssi2use);
}
public Beacon getSuperBeacon() {
return beacon;
}
}
RangingService.java
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "Service onCreate");
beaconManager.setDebug(true);
RangedBeacon.setSampleExpirationMilliseconds(2200);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.bind(this);
}
我只听一个特定的信标。
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() == 1) {
Beacon beacon = beacons.iterator().next();
handleBeaconInRange(beacon);
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region(RANGE_REGION_ID, null, null, null));
} catch (RemoteException e) {
Log.e(TAG, "Exception on onbeaconServiceConnect", e);
}
}
handleBeaconInRange() 还需要处理不同的距离,但这会产生日志。
private void handleBeaconInRange(Beacon beacon) {
int rssi2use = beacon.getRssi();
if (rssi2use == 127) {
Log.i(TAG, "Using last Rssi " + lastRssi + " instead of 127");
rssi2use = lastRssi;
} else {
lastRssi = beacon.getRssi();
}
MyBeacon myBeacon = new MyBeacon(beacon, rssi2use);
double distance = myBeacon.getDistance();
Log.i(TAG, "RSSI: " + rssi2use + " Distance: " + distance + " meters");
}
日志:
05-08 09:25:47.675 27646-29040/ I/RangingService? Using last Rssi -56 instead of 127
05-08 09:25:47.675 27646-29040/ I/RangingService? RSSI: -56 Distance: 0.7040448636262671 meters
05-08 09:25:48.839 27646-29041/ I/RangingService? RSSI: -56 Distance: 0.7040448636262671 meters
05-08 09:25:49.982 27646-29042/ I/RangingService? RSSI: -58 Distance: 0.97085 meters
05-08 09:25:51.121 27646-29043/ I/RangingService? Using last Rssi -58 instead of 127
05-08 09:25:51.121 27646-29043/ I/RangingService? RSSI: -58 Distance: 0.97085 meters
05-08 09:25:52.263 27646-29044/ I/RangingService? Using last Rssi -58 instead of 127
05-08 09:25:52.263 27646-29044/ I/RangingService? RSSI: -58 Distance: 0.97085 meters
05-08 09:25:53.408 27646-29045/ I/RangingService? RSSI: -55 Distance: 0.5879588872684474 meters
05-08 09:25:54.575 27646-29046/ I/RangingService? Using last Rssi -55 instead of 127
05-08 09:25:54.575 27646-29046/ I/RangingService? RSSI: -55 Distance: 0.5879588872684474 meters
05-08 09:25:55.701 27646-29047/ I/RangingService? RSSI: -54 Distance: 0.4893928979531776 meters
05-08 09:25:56.858 27646-29064/ I/RangingService? RSSI: -61 Distance: 1.1474711863884917 meters
05-08 09:25:57.991 27646-29074/ I/RangingService? Using last Rssi -61 instead of 127
05-08 09:25:57.992 27646-29074/ I/RangingService? RSSI: -61 Distance: 1.1474711863884917 meters
05-08 09:25:59.130 27646-29075/ I/RangingService? RSSI: -46 Distance: 0.09846874009910023 meters
05-08 09:26:00.247 27646-29081/ I/RangingService? Using last Rssi -46 instead of 127
05-08 09:26:00.247 27646-29081/ I/RangingService? RSSI: -46 Distance: 0.09846874009910023 meters
05-08 09:26:01.392 27646-29085/ I/RangingService? RSSI: -49 Distance: 0.18521700814366415 meters
05-08 09:26:02.534 27646-29086/ I/RangingService? Using last Rssi -49 instead of 127
05-08 09:26:02.534 27646-29086/ I/RangingService? RSSI: -49 Distance: 0.18521700814366415 meters
05-08 09:26:03.680 27646-29087/ I/RangingService? Using last Rssi -49 instead of 127
05-08 09:26:03.680 27646-29087/ I/RangingService? RSSI: -49 Distance: 0.18521700814366415 meters
05-08 09:26:04.823 27646-29088/ I/RangingService? RSSI: -33 Distance: 0.0035551625558338114 meters
05-08 09:26:05.967 27646-29089/ I/RangingService? RSSI: -37 Distance: 0.011161878866100936 meters
【问题讨论】:
-
听起来您从移动设备上的硬件或蓝牙驱动程序固件中得到了错误的读数。你能展示你的 RangingService 代码,它会吐出这些日志行吗?您是手动计算距离还是使用内置的 Android 信标库距离计算器?内置的库距离计算器已经排除了 RSSI 读数的前 10% 和后 10%,所以如果您使用它的距离计算,这表明超过 10% 的读数具有这个无效的 RSSI 值。
-
@davidgyoung 我使用默认库内置计算器,但我将 sampleExpirationMilliseconds 设置为 2200。但这不会影响结果。应您的要求,我将编辑我的问题。
-
@davidgyoung 实际上,为了解决这个问题,我简化了 Beacon 中的 getDistance() 方法,以查看库是否与这些数字有关。
-
您能告诉我您使用的手机型号和Android操作系统版本吗?看来您获得的 RSSI 读数超过 10% 为 127。我可以对库进行修复,以自动过滤掉这样不合理的 RSSI 读数,但我首先想了解哪些设备有问题。
-
@davidgyoung 我正在使用 LG G3 S Android 4.4.2 / 5.0.2 两个版本都显示这种行为。我将使用来自同一制造商的不同硬件对此进行测试。我正在使用 Sensorberg 的最小版本。这可能是发送错误信号的信标相关问题吗?
标签: android ibeacon rssi altbeacon