altbeacon 库返回的 rssi 127 弄乱了距离
rssi returned by altbeacon library 127 messes up distance
我正在开发一个应用程序,它根据信标的范围(例如位置 < .5 | 位置 < 2 | 位置 < 10)在进入不同区域时创建某些消息。我在记录距离和 rssi 时遇到了奇怪的行为。目前,如果 RSSI 为 127,我会将 RSSI 替换为最后接收到的 RSSI。这是唯一一个看起来完全不合适的值。
问题
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
如果您查看距离,它会在 127 的 rssi 之后或之后的每次计算中随机出现尖峰。我不明白为什么 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
这与图书馆无关。这似乎与使用的设备有关,固件或适配器都吐出错误的读数。
感谢@davidgyoung 帮助解决这个问题。
我正在开发一个应用程序,它根据信标的范围(例如位置 < .5 | 位置 < 2 | 位置 < 10)在进入不同区域时创建某些消息。我在记录距离和 rssi 时遇到了奇怪的行为。目前,如果 RSSI 为 127,我会将 RSSI 替换为最后接收到的 RSSI。这是唯一一个看起来完全不合适的值。
问题
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
如果您查看距离,它会在 127 的 rssi 之后或之后的每次计算中随机出现尖峰。我不明白为什么 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
这与图书馆无关。这似乎与使用的设备有关,固件或适配器都吐出错误的读数。
感谢@davidgyoung 帮助解决这个问题。