Alt Beacon Android不稳定

时间:2015-07-01 22:43:36

标签: android bluetooth bluetooth-lowenergy android-bluetooth altbeacon

我正在构建一个基于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,并且功率似乎设置为最大。我应该使用不同的设备并尝试使用它吗?我看到其他一些帖子建议关闭我做的wifi,这个日志来自试用无线关闭。

我应该注意的一点是,我使用应用程序子类中的以下代码块增加了扫描频率:

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)标志的情况下运行了这个。这是resulting log

更新2:

我将我的灯塔切换为仅为iBeacon广播,问题似乎消失了大约10分钟。不幸的是,问题迅速恢复浏览日志,我现在看到的是完全不同的。可以看到日志here。我的假设是问题在于这一行:

07-01 21:46:31.035    2499-2499/com.avtar.truckkeeper D/CycledLeScanner﹕ cancel wakeup alarm: PendingIntent{41f32070: android.os.BinderProxy@41d8f750}

非常感谢任何想法/帮助!

1 个答案:

答案 0 :(得分:2)

基于对答案底部链接的“结果日志”的分析,我怀疑有几件事正在进行:

  1. 发送信标被配置为发送AltBeacon和iBeacon分组。
  2. Android Beacon Library尚未配置为检测iBeacon数据包,仅检测默认的AltBeacon数据包。
  3. 发送信标处于可连接模式。
  4. 当信标处于可连接模式时,Digiland(P-O-S)平板电脑每个扫描周期只能检测来自每个不同蓝牙LE设备的一个数据包。 (其他几款Android机型也采用这种方式,包括Nexus 4和Moto G)
  5. 扫描间隔已配置为超长 - 每10秒扫描一秒钟。
  6. 所有这些事情共同造成了一场完美风暴,导致了这些问题:

    由于(4)中描述的缺陷以及如(3)中所述信标处于可连接模式的事实,这意味着每个扫描周期仅拾取一个分组。因为信标正在发送如(1)中所述的交织广告,这意味着该分组将有50%的机会成为iBeacon分组。如果它是iBeacon数据包,因为库尚未配置为如(2)中所述检测iBeacons,则在该周期中将不会检测到。并且由于扫描周期为10秒,如5中所述,这将导致间歇性区域退出和重新输入。 (如果在10秒内未看到信标,则库会触发区域退出。)

    更改任何一项内容可能会导致问题消失:

    1. 重新配置您的信标以关闭iBeacon传输(或配置磁带库以检测iBeacon传输。)

    2. 让您的信标的可连接性超时更短 - 例如60秒后。一旦它不再可连接,平板电脑将能够在每个扫描周期中获得多个数据包,问题就会消失。

    3. 缩短扫描周期的时间。如果您在前台扫描时间之间保留默认值为1100毫秒的扫描时间和0毫秒,那么在10秒区域超时触发之前,库将有9个周期来检测信标。在9个周期内未检测到信标的50-50几率将变为0.5 ^ 9 = 0.1%几率。