2
votes

i am developing a android app and detect beacons every 1 seconds, I use altbeacon library to implement the service, I test this app using 200 beacons just put aside from me, but it seems that my app only detect 40-80 number of beacons, not nearly 200 beacons, I thought it might because of beacon's advertising interval, so I adjust all the beacon's interval as 300ms, and finally I still get similar results(less than 80), Is anyone knows what's wrong happens with it?

here I attach my main code:
I first init beacomanager with layout and bind the service:

    private void initManager(){
    beaconManager = BeaconManager.getInstanceForApplication(getActivity().getApplicationContext());

    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));

    beaconManager.setForegroundScanPeriod(1000);
    beaconManager.setForegroundBetweenScanPeriod(0);

    beaconManager.bind(this);

    try {
        if (beaconManager.isAnyConsumerBound()) {
            beaconManager.updateScanPeriods();
        }
    } catch (RemoteException e) {
        Log.e("RECO", "update scan periods error", e);
    }
    }

I then get the result from onBeaconServiceConnect and send it to mainthread (I create a beacon to startranigng)

    @Override
public void onBeaconServiceConnect() {
    Log.d(TAG, "onBeaconServiceConnect called");
    beaconManager.addRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            Log.i("RECORangingActivity", "didRangeBeaconsInRegion() region: " + region.getUniqueId() + ", number of beacons ranged: " + beacons.size());


            // send bacon to main_activity to update UI
            ArrayList<Beacon> scanedBeacon = new ArrayList<Beacon>(beacons);
            // rank beacon by RSSI
            Collections.sort(scanedBeacon, new Comparator<Beacon>() {
                public int compare(Beacon one, Beacon other) {
                    return Integer.compare(other.getRssi(), one.getRssi());
                }
            });

            Intent intent = new Intent(action);
            intent.putParcelableArrayListExtra("RecoBeacon", scanedBeacon);
            getActivity().sendBroadcast(intent);
        }
    });
}

and finally, I create startranging and stopranging function to control it and put startranging into a thread inside onclicklistener;

    private void startRanging(){
    Log.d(TAG, "start Ranging beacons");

    try {
        beaconRegion = new Region("MyBeacons", Identifier.parse(RECO_UUID), null, null);
        beaconManager.startMonitoringBeaconsInRegion(beaconRegion);
        beaconManager.startRangingBeaconsInRegion(beaconRegion);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

private void stopRanging(){
    Log.d(TAG, "stop Ranging beacons");
    try {
        beaconManager.stopMonitoringBeaconsInRegion(beaconRegion);
        beaconManager.stopRangingBeaconsInRegion(beaconRegion);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}



    startBT.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        startBT.setText("Running");
        startBT.setEnabled(false);

        Thread t1 = new Thread(){
            @Override
            public void run() {
                startRanging();
            }
        };
        t1.start();
    }
    })  

and the detected result is as follows:

    08-21 06:33:51.373 10408-11779/com.example.haoch.groupsI/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 60
    08-21 06:33:52.394 10408-11780/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 49
    08-21 06:33:53.416 10408-11781/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 43
    08-21 06:33:54.475 10408-11782/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 58
    08-21 06:33:55.515 10408-11783/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 64
    08-21 06:33:56.541 10408-11784/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 64
    08-21 06:33:57.566 10408-11785/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 46
    08-21 06:33:58.599 10408-11786/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 68
    08-21 06:33:59.637 10408-11788/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 68
    08-21 06:34:00.665 10408-11789/com.example.haoch.groupse I/RECORangingActivity: didRangeBeaconsInRegion() region: MyBeacons, number of beacons ranged: 72  

Apparently, this is the wrong detecting result, it should detect nearly 200 beacons but I only get quite small number of beacons.

1

1 Answers

0
votes

The bad news is that the library is probably not what is limiting you here. It's the bluetooth stack on your phone. The number of beacons you can successfully scan simultaneously is largely dependent on two factors:

  1. The bluetooth stack (hardware, firmware, and operating system software) of the Android device model being used.
  2. The CPU power of the device. The first factor is almost always the limiting factor. The second factor only comes into play if there is heavy processing going on in the beacon callbacks (or of debug logging is turned on in the library.)

I have run tests on a number of Samsung device models, since these are some of the most common on the market. The Galaxy S5 (Android 6) has better performance than the S8 (Android 7) or S9 (Android 8). I have seen it detect about 350 unique beacon transmissions over a 5 minute period, but not all of these get detected in the same ranging cycle -- that is typically fewer than 100. Each ranging cycle a different set of beacons get detected, but over time all of them do.

There is a big difference from one device model to the next, and price is no predictor. The S8 and S9 detect fewer than half as many beacons in a single cycle as the S5. The Nexus 5X (Android 6) is simply terrible, and detects only 10% as many beacons as the S5 The Huawei P9 (Android 7) performs similarly to the Samsung Galaxy S8 and S9.

To confirm that the phone model is the key factor, try running the exact same app on a few different phones at the same time and count how many beacons you detect. You will likely see a big difference between device models.