2015-05-08 103 views
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 
+0

这听起来像是你的硬件或移动设备上的蓝牙驱动程序固件读取不好的读数。你可以显示你的代码RangingService吐出这些日志行吗?您是手动计算距离还是使用内置Android Beacon库距离计算器?内置的图书馆距离计算器已经抛出了RSSI读数的前10%和最后10%,因此如果您正在使用它的距离计算,这表明超过10%的读数具有无效的RSSI值。 – davidgyoung

+0

@davidgyoung我使用默认的库内置计算器,但我将sampleExpirationMilliseconds设置为2200.但是这并不影响结果。 由于您的要求,我会编辑我的问题。 – itsJASPERr

+0

@davidgyoung实际上,为了解决这个问题,我简化了Beacon中的getDistance()方法,以查看该库是否与这些数字有关。 – itsJASPERr

回答

0

这是不相关的库。这似乎与使用过的设备有关,无论是固件还是适配器都吐出了错误的读数。

谢谢@davidgyoung帮助清除此问题。