Working with ranging beacons and its working fine, well theoritically. I have 3 beacons, and a simple algorithm to detect only one beacon at a time at the shortest distance, but due to the continious fluctuation of of RSSI values I am ending up detecting the other beacons VERY frequently. Well that will not be so harmful if I can 'pause' a little more between detection. My betweenscan perdiod is, setForegroundBetweenScanPeriod(0l). Now the question is, should I increase the setForegroundBetweenScanPeriod() to achieve that 'pause' property or handle it manually using some sort of timer? Is the algorithm correct to detect one beacon that is at the shortest distance? Here is my code
protected void onCreate(Bundle savedInstanceState) {
...
beaconManager.setForegroundScanPeriod(1100l);
beaconManager.setForegroundBetweenScanPeriod(0l);
beaconManager.bind(this);
...
}
@Override
public void onBeaconServiceConnect(){
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
//find the beacon with shortest distance
int idx = -1; //when no beacon is there
double min = Double.MAX_VALUE;
for (int i = 0; i < beaconArray.length; i++) {
double d = ((Beacon) beaconArray[i]).getDistance();
if (d < min) {
min = d;
idx = i; //1st beacon in the array
}
}
if (count == 0 && idx != -1) {
//show the data associated with the beacon
}
Aucun commentaire:
Enregistrer un commentaire