我正在构建一个基于Alt-Beacon的android应用程序。我应该以我的测试设备是运行android 4.4的Digiland(P-O-S)平板电脑为前提。
我正在使用Radius Networks USB信标和他们的Alt-beacon库,可以在这里找到:https://github.com/AltBeacon/android-beacon-library
在我自己的应用程序和库中提供的参考应用程序中,我都看到信标的显著不稳定性/极慢的检测时间。例如,您可以在下面看到参考应用程序的日志。平板电脑一直坐在距离信标不超过1/2米的地方。
以前有人见过这种行为吗?我做错什么了吗?信标上的广播速率似乎设置为10Hz,功率似乎设置为最大值。我应该换个设备试试吗?我看到其他一些帖子建议关闭无线网络,我也这么做了,这个日志来自一个关闭无线网络的试用。
我应该注意的一点是,我在应用程序子类中增加了以下代码块的扫描频率:
beaconManager.setBackgroundBetweenScanPeriod(9000l);
beaconManager.setBackgroundScanPeriod(1000l);
beaconManager.setForegroundBetweenScanPeriod(9000l);
beaconManager.setForegroundScanPeriod(1000l);
try{
beaconManager.updateScanPeriods();
}catch (RemoteException e){
e.printStackTrace();
}
我不确定这是否是不正确的,但当我删除它时,我仍然会看到下面日志中描述的相同行为,只是在更长的时间内。
如果有人给我任何建议,我都会非常感激,因为我觉得我在这上面打转!
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.
需要注意的一件更有趣的事情是,当我在日志中为onScanResult进行筛选时,我看到的是:
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
00:07:80设备是我的指路明灯,但我不知道24:4B:03设备是什么时候。有人知道我如何才能获得有关该设备的更多数据吗?它可能干扰了我的实际信号吗?我试过使用两种
Region region = new Region("backgroundRegion",
Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), null, null);
和
Region region = new Region("backgroundRegion",null, null, null);
不幸的是,我得到了这两种变化的随机波动。
更新:
我还在beaconManager.setDebug(true)标志被激活的情况下运行了这个。这是生成的日志
更新2:
我把我的信标切换到只为iBeacon广播,这个问题似乎消失了大约10分钟。不幸的是,问题很快又出现了。翻看日志,我现在看到的完全不同了。日志可以在这里看到。我的假设是问题出在这条线上:
07-01 21:46:31.035 2499-2499/com.avtar.truckkeeper D/CycledLeScanner﹕ cancel wakeup alarm: PendingIntent{41f32070: android.os.BinderProxy@41d8f750}
如有任何想法/帮助,我们将不胜感激!
根据对答案底部链接的"结果日志"的分析,我怀疑发生了一些事情:
- 发送信标被配置为发送AltBeacon和iBeacon分组
- 安卓信标库尚未配置为检测iBeacon数据包,只有默认的AltBeacon数据包
- 发送信标处于可连接模式
- 当信标处于可连接模式时,Digiland(P-O-S)平板电脑在每个扫描周期只能检测到来自每个不同蓝牙LE设备的一个数据包。(包括Nexus 4和Moto G在内的其他几款安卓机型也是如此)
- 扫描间隔被配置为超长——每10秒扫描一秒
所有这些因素加在一起形成了一场完美的风暴,导致了这些问题:
由于(4)中所述的缺陷以及(3)中所描述的信标处于可连接模式的事实,这意味着每个扫描周期将只拾取一个数据包。因为信标正在发送如(1)中所述的交织广告,这意味着该分组将是iBeacon分组的可能性为50%。如果它是iBeacon数据包,因为库没有被配置为检测iBeacon,如(2)中所述,所以在该周期中将不会有检测。由于扫描周期如第5节所述为10秒,这将导致间歇性区域退出和重新进入。(如果在10秒内没有看到信标,则库触发区域退出。)
更改其中任何一项都可能使问题消失:
-
重新配置您的信标以关闭iBeacon传输(或配置库以检测iBeacon发送。)
-
缩短信标的可连接性超时时间,例如60秒后。一旦它不再可连接,平板电脑将能够在每个扫描周期中获得多个数据包,问题就会消失。
-
缩短扫描周期的时间长度。如果在前台保留1100ms扫描时间和0ms扫描时间之间的默认值,则在10秒区域超时触发之前,库将有9个周期来检测信标。在9个周期内未检测到信标的50%几率将变为0.5^9=0.1%几率。