MindBrain
MindBrain

Reputation: 7768

AltBeacon Library shows beacons only once and then stops showing them

I experience an issue and can reproduce it on different devices with different Android OS. I get the expected behaviour with iBeacon scanning for the first time. When I scan the next time I get no Beacons. The result list in delegate is empty. I printed a count on the setRangeNotifier with the size of the beacons but apparently after it only shows the beacons size to be 1 for the first time after which it continually displays a 0.

beaconManager.setRangeNotifier(new RangeNotifier() {
    @Override
    public void didRangeBeaconsInRegion(final Collection<Beacon> beacons, Region region) {
       Log.d("Beacons count",beacons.size());
    }
});

Output: Beacons Count 1 Beacons Count 0 Beacons Count 0 Beacons Count 0

My ranging period and scanning period is as below

beaconManager.setBackgroundScanPeriod(1000l);
beaconManager.setBackgroundBetweenScanPeriod(31000l);

Upvotes: 2

Views: 1009

Answers (3)

davidgyoung
davidgyoung

Reputation: 64941

Upon further reflection I think it is the scan intervals that were the problem. The scan intervals reported were to spend 1 second looking for beacons every 32 seconds. This is not enough of a duty cycle, especially for beacons that transmit at only 1Hz. Not all transmissions are received due to radio noise, and it is important that scan durations be 1100 ms or more in order to prevent the transmission from straddling the boundary where the scanner is starting up or shutting down.

Upvotes: 0

davidgyoung
davidgyoung

Reputation: 64941

This is not expected behavior, and I have not seen this on Android 4.4 on other devices. Based on limited information, it is possible it could be an app issue, or it may be an issue with the 4.4 CynogenMod ROM for the One Plus. See my other answer with a detailed test case for a reference device (Nexus 5).

To eliminate the possibility of an app issue, try using the Locate app, which is based on the same library and see if you get the same results.

Upvotes: 1

davidgyoung
davidgyoung

Reputation: 64941

I have tried to reproduce the symptoms you describe, but have been unable to do so on a Nexus 5 with Android 5 and a transmitting RadBeacon USB.

Reference application modifications:

  • Added these lines to the BeaconReferenceApplication onCreate() method:

    beaconManager.setBackgroundBetweenScanPeriod(1000l);
    beaconManager.setBackgroundBetweenScanPeriod(31000l);
    beaconManager.setAndroidLScanningDisabled(true);
    BeaconManager.setDebug(true);
    

The third line above is needed because I was testing on a Nexus 5 with Android 5 and I wanted to exercise the 4.x scanning APIs, like you would be done on a 4.4 phone.

  • Added this line to the RangingActivity didRangeBeaconsInRegion callback:

    Log.d(TAG, "ranged beacon: "+firstBeacon.toString());
    

Testing steps:

  • Enable a RadBeacon USB transmitting at 10 HZ.

  • Log the results with:

    $ /Users/dyoung/sdk-android-studio/platform-tools/adb logcat -v time | grep "anged beacon"
    
  • Run the reference app, started ranging in the foreground, and after three seconds put it into the background. See the following logging results:

    03-01 08:39:00.146 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:39:01.282 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:39:02.482 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:39:03.515 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:39:12.148 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:39:44.274 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:40:16.179 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:40:48.239 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:41:20.272 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:41:52.205 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    03-01 08:42:24.202 D/RangingActivity(11146): ranged beacon: id1: 04ff791e-f83b-434b-8031-1b3e72bdbcb7 id2: 1 id3: 1
    

As you can see, the callbacks come every 1.1 seconds in the foreground, and every 32 seconds in the background. This is as expected.

If you cannot repeat the above steps using the reference application on the OnePlus device with Cyanogenmod 4.4, then the issue may be with the ROM for that device. If you can confirm this and capture a full Logcat output for the period where the callbacks don't come (with debug turned on as described above), then please open an issue at http://github.com/AltBeacon/android-beacon-library/issues and attach a copy of the log capture.

Upvotes: 1

Related Questions