Reputation: 2313
I am building an android application based on the Alt Beacon. I should preface this with the fact that my test device is a Digiland (P-O-S) tablet running android 4.4.
I am using the Radius Networks USB beacon and their Alt Beacon library found here: https://github.com/AltBeacon/android-beacon-library
In both my own application and in the reference application provided with the library I am seeing significant instability / extremely slow detection times for the beacon. For example, you can see the reference application's log below. The tablet is sitting no more than 1/2 meter away from the beacon the whole time.
Has anyone seen this behavior before? Am I doing something wrong? The broadcast rate on the beacon appears to be set to 10Hz and the power seems to be set to maximum. Should I get a different device and try it on that? I saw some other posts suggested turning off the wifi which I did, and this log is from a trial with the wifi off.
One thing I should note is that I have increased the scan frequency with the following block of code in the application subclass:
beaconManager.setBackgroundBetweenScanPeriod(9000l);
beaconManager.setBackgroundScanPeriod(1000l);
beaconManager.setForegroundBetweenScanPeriod(9000l);
beaconManager.setForegroundScanPeriod(1000l);
try{
beaconManager.updateScanPeriods();
}catch (RemoteException e){
e.printStackTrace();
}
I am not sure if this is done improperly, but when I remove it, I still see the same behavior described in the log below, just over a somewhat longer period of time.
Any advice people have would be much appreciated since I feel like I am spinning my wheels on this!
07-01 15:23:59.005 10771-10771/org.altbeacon.beaconreference D/ReferenceApplication﹕ setting up background monitoring for beacons and power saving
07-01 15:23:59.655 10771-10816/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:23:59.655 10771-10816/org.altbeacon.beaconreference D/ReferenceApplication﹕ auto launching MainActivity
07-01 15:24:20.154 10771-11297/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:24:39.174 10771-11486/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:25:00.132 10771-11647/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:25:09.472 10771-11730/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:25:30.123 10771-11871/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:25:39.173 10771-11954/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:26:00.065 10771-12070/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:26:29.099 10771-12083/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:26:29.100 10771-12083/org.altbeacon.beaconreference D/ReferenceApplication﹕ Sending notification.
07-01 15:26:40.112 10771-12096/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:27:19.120 10771-12127/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:27:19.120 10771-12127/org.altbeacon.beaconreference D/ReferenceApplication﹕ Sending notification.
07-01 15:27:40.041 10771-12208/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:27:59.110 10771-12786/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:28:30.144 10771-13052/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:28:39.202 10771-13131/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:28:50.133 10771-13226/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:29:09.125 10771-13375/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:29:30.119 10771-13452/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:29:49.144 10771-13473/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:30:00.060 10771-13510/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:30:19.134 10771-13552/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:30:19.135 10771-13552/org.altbeacon.beaconreference D/ReferenceApplication﹕ Sending notification.
07-01 15:30:30.096 10771-13560/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:31:09.124 10771-13575/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:31:09.125 10771-13575/org.altbeacon.beaconreference D/ReferenceApplication﹕ Sending notification.
07-01 15:31:20.110 10771-13576/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:31:29.101 10771-13578/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
07-01 15:31:29.101 10771-13578/org.altbeacon.beaconreference D/ReferenceApplication﹕ Sending notification.
07-01 15:32:40.101 10771-13647/org.altbeacon.beaconreference D/ReferenceApplication﹕ did exit region
07-01 15:32:59.131 10771-13651/org.altbeacon.beaconreference D/ReferenceApplication﹕ did enter region.
One more interesting thing to note is that when I do a filter for onScanResult in the logs I see this:
07-01 15:45:49.074 10771-10839/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=24:4B:03:2E:00:D9 RSSI=-91
07-01 15:45:49.117 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=00:07:80:1E:7E:B7, rssi=-56
07-01 15:45:49.120 10771-10784/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=00:07:80:1E:7E:B7 RSSI=-56
07-01 15:45:49.365 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=62:44:C6:64:4D:A5, rssi=-76
07-01 15:45:49.368 10771-10783/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=62:44:C6:64:4D:A5 RSSI=-76
07-01 15:45:59.082 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=62:44:C6:64:4D:A5, rssi=-77
07-01 15:45:59.084 10771-10784/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=62:44:C6:64:4D:A5 RSSI=-77
07-01 15:45:59.130 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=00:07:80:1E:7E:B7, rssi=-59
07-01 15:45:59.133 10771-10783/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=00:07:80:1E:7E:B7 RSSI=-59
07-01 15:45:59.140 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=24:4B:03:2E:00:D9, rssi=-76
07-01 15:45:59.141 10771-10839/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=24:4B:03:2E:00:D9 RSSI=-76
07-01 15:46:09.115 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=00:07:80:1E:7E:B7, rssi=-58
07-01 15:46:09.117 10771-10783/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=00:07:80:1E:7E:B7 RSSI=-58
07-01 15:46:09.124 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=24:4B:03:2E:00:D9, rssi=-86
07-01 15:46:09.126 10771-10839/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=24:4B:03:2E:00:D9 RSSI=-86
07-01 15:46:09.135 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=62:44:C6:64:4D:A5, rssi=-76
07-01 15:46:09.139 10771-10784/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=62:44:C6:64:4D:A5 RSSI=-76
07-01 15:46:19.060 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=24:4B:03:2E:00:D9, rssi=-91
07-01 15:46:19.062 10771-10839/org.altbeacon.beaconreference D/BluetoothAdapter﹕ onScanResult() - Device=24:4B:03:2E:00:D9 RSSI=-91
07-01 15:46:19.092 1425-1495/? D/BtGatt.GattService﹕ onScanResult() - address=00:07:80:1E:7E:B7, rssi=-64
The 00:07:80 device is my beacon, but I have no idea whatsoever when the 24:4B:03 device is. Does anyone know how I can get more data about this device? Is it possible that it is interfering with my actual signal? I have tried using both
Region region = new Region("backgroundRegion",
Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), null, null);
and
Region region = new Region("backgroundRegion",null, null, null);
Unfortunately I get this random fluctuation with both variations.
UPDATE:
I also ran this with the beaconManager.setDebug(true) flag activated. Here is the resulting log
UPDATE 2:
I switched my beacon to only broadcast for iBeacon and the problem seemed to go away for about 10 minutes. Unfortunately the problem quickly returned. Looking through the logs, what I am seeing is quite different now. The logs can be seen here. My assumption is that the problem is with this line:
07-01 21:46:31.035 2499-2499/com.avtar.truckkeeper D/CycledLeScanner﹕ cancel wakeup alarm: PendingIntent{41f32070: android.os.BinderProxy@41d8f750}
Any thoughts/help would be much appreciated!
Upvotes: 2
Views: 1449
Reputation: 64916
I suspect several things are going on based an analysis of the "resulting log" linked at the bottom of the answer:
All of these things together are creating a perfect storm that is causing these problems:
Because of the flaw described in (4) and the fact that the beacon is in connectable mode as described in (3), this means that only one packet will get picked up per scan cycle. Because the beacon is sending interleaved advertisements as described in (1), that means there is a 50-50 chance that this packet will be an iBeacon packet. If it is an iBeacon packet, because the library has not been configured to detect iBeacons as described in (2), there will be no detections in that cycle. And because the scan cycle is 10 seconds long as described in 5, this will cause intermittent region exits and re-entries. (If no beacon is seen in 10 seconds, the library triggers a region exit.)
Changing any one of these things will probably make the issue go away:
Re-configure your beacon to turn off iBeacon transmissions (or configure the library to detect iBeacon transmissions.)
Make your beacon's connectability timeout shorter -- e.g. after 60 seconds. Once it is no longer connectable, the tablet will be able to get multiple packets in each scan cycle and the problem will go away.
Reduce the length of time of the scan cycle. If you leave the defaults of 1100ms scan time with 0ms between scan time in the foreground, then the library will have 9 cycles to detect the beacon before the 10 second region timeout fires. The 50-50 odds of not detecting the beacon in 9 cycles will then become 0.5^9 = 0.1% chance.
Upvotes: 2