1
我正在研究一個應用程序,該程序根據信標範圍(例如位置<.5 |位置< 10 |位置10)輸入不同區域時創建特定消息。記錄距離和rssi時我遇到了一個奇怪的行爲。目前我正在用最後接收的RSSI取代RSSI(如果它是127)。這是唯一看起來完全不合適的值。由altbeacon函數庫返回的rssi 127提高了距離
的問題
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 簡化距離calulation的清理的RSSI
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);
}
我只聽一個speficic燈塔。
@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 Beacon庫距離計算器?內置的圖書館距離計算器已經拋出了RSSI讀數的前10%和最後10%,因此如果您正在使用它的距離計算,這表明超過10%的讀數具有無效的RSSI值。 – davidgyoung
@davidgyoung我使用默認的庫內置計算器,但我將sampleExpirationMilliseconds設置爲2200.但是這並不影響結果。 由於您的要求,我會編輯我的問題。 – itsJASPERr
@davidgyoung實際上,爲了解決這個問題,我簡化了Beacon中的getDistance()方法,以查看該庫是否與這些數字有關。 – itsJASPERr