蓝牙LE广告周期性地启动和停止时失败 [英] Bluetooth LE advertising fails when started and stopped cyclically

查看:175
本文介绍了蓝牙LE广告周期性地启动和停止时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了蓝牙LE广告,即使用Android手机作为BLE外围"设备.启动和停止恒定的广告一次可以很好地工作,但是如果我想实际传输一些变化的数据,则需要一个周期地启动,停止和重新启动广告,并始终更改广告包.

I've tried out Bluetooth LE advertising i.e. using an Android phone as a BLE "peripheral" device. Starting and stopping a constant advertising once works fine but if I'd like to actually transmit some varying data I would need to start, stop and restart the advertising in a cycle and always change the advertising package.

我正在使用以下方法:
BluetoothLeAdvertiser.stopAdvertising()

I'm using these methods of course:
BluetoothLeAdvertiser.startAdvertising()
BluetoothLeAdvertiser.stopAdvertising()

至少在Motorola Moto G 4G第二代上. (XT1072)和Android 5.0.2,该循环仅运行了一段时间,然后蓝牙堆栈出现了问题,无法再开始新的广告.快速运行循环会很快发生;如果运行缓慢,则会花费更多时间,因此可能与缓冲区已满有关.

At least on a Motorola Moto G 4G 2nd gen. (XT1072) with Android 5.0.2 the cycle only runs for a while and then something goes wrong in the Bluetooth stack and a new advertising can no longer be started. When running the cycle quickly this happens quickly and if running slowly it takes more time so it could be related to some buffer filling up.

我的问题是:在摩托罗拉以外的其他设备上也会发生这种情况吗?

My question is: Does this also happen on other devices than Motorola?

(当然也欢迎其他任何相关评论.)

(And any other related comments are of course welcome.)

从理论上讲,它可能取决于某些制造商特定的HAL实现等.因此,我想知道我是否应该再购买另一台设备来进行此工作,因为来自Google/Motorola的任何修复程序当然都需要一些时间

Theoretically it could be dependent on some manufacturer specific HAL implementation etc. so I'd like to know if I should just get another device to be able to work on this as any fix from Google/Motorola would take some time of course.

此测试应用.可以用来尝试:

This test app. can be used to try this out:

https://bitbucket.org/MarkusKauppinen/bleadvertisertest

如果一切正常,它会很高兴永远保持广告投放,并且如果此问题再次出现,它会在几分钟左右的时间内显示一个对话框.如果您的设备根本不支持Bluetooth LE广告或BLE,它将崩溃. (这只是一个快速而肮脏的测试应用程序.)

If everything goes fine it'll happily keep advertising for ever and if this problem reproduces, it will show a dialog within a couple of minutes or so. If your device doesn't support Bluetooth LE advertising or BLE at all it will just crash. (It's just a quick-and-dirty test app.)

另一个简单的重现方法是从 https://github运行"bluetoothadvertiser"应用程序. com/devunwired/accessory-samples ,并保持快速点击UI上的更新广告"按钮一段时间.

Another easy way to reproduce this is to run the "bluetoothadvertiser" app from https://github.com/devunwired/accessory-samples and just keep quickly tapping on the "Update advertisement" button on the UI for a while.

其他详细信息:

在Lollipop中添加了对蓝牙LE外设模式的支持(广告需要),而在4.x中不可用.仅某些设备支持外设模式.兼容性至少包含在以下内容中:

The Bluetooth LE peripheral mode support (needed for advertising) was added in Lollipop and is not available in 4.x. Only certain devices have the peripheral mode support. Compatibility is covered at least in:

https://altbeacon.github.io/android -beacon-library/beacon-transmitter-devices.html 支持Android 5 BLE外设模式的芯片组/设备 在Android 5上支持BLE外设角色的芯片组

例如,以下设备应获得支持:摩托罗拉Moto E 4G(2015),摩托罗拉Moto G 4G(第二代),索尼Xperia M4 Aqua,中兴Blade S6,摩托罗拉Moto X(2014),三星银河S6, Google Nexus 6,Google Nexus 9,HTC One M9,三星Galaxy S6 Edge.

For example these devices should have the support: Motorola Moto E 4G (2015), Motorola Moto G 4G (2nd gen.), Sony Xperia M4 Aqua, ZTE Blade S6, Motorola Moto X (2014), Samsung Galaxy S6, Google Nexus 6, Google Nexus 9, HTC One M9, Samsung Galaxy S6 Edge.

对于脏细节",在发生这种情况之前,我总是可以在LogCat中看到"GKI_Exception":

As for the "dirty details" I can always see a "GKI_Exception" in LogCat before this happens:

GKI_exception():65524 getbuf:缓冲区不足

GKI_exception(): 65524 getbuf: out of buffers

在第一个"GKI_Exception"之后不久,广告就会失败,并显示AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR.线...

Soon after the first "GKI_Exception" the advertisement fails with AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR. The line...

E/BtGatt.btif? ### ASSERT: 外部/蓝牙/bluedroid/main/../btif/src/btif_gatt_client.c行 803上下文传输失败! (3)###

E/BtGatt.btif? ### ASSERT : external/bluetooth/bluedroid/main/../btif/src/btif_gatt_client.c line 803 Context transfer failed! (3) ###

...可能有关,但我对BlueDroid不熟悉.所说的断言在这里:

...is probably relevant but I'm not familiar with BlueDroid. The said assert is here:

https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.0.2_r1/btif/src/btif_gatt_client.c#803

一些可能相关的问题:
https://code.google.com/p/android/issues/detail?id = 65455 <-我为此添加了一些注释和日志文件.
https://code.google.com/p/android-developer-preview/issues/detail?id = 1753
扫描大量BLE标签
三星S4上的蓝牙崩溃

Some possibly related problems:
https://code.google.com/p/android/issues/detail?id=65455 <-- I added some comments and log files to this one.
https://code.google.com/p/android-developer-preview/issues/detail?id=1753
Scanning large number of BLE Tags
Bluetooth Crash on Samsung S4

推荐答案

我在Moto G 2nd Gen上测试了您的应用,并遇到了同样的问题.

I tested your app on a Moto G 2nd Gen and run into the same problem.

我在运行Android 6.0的Nexus 9平板电脑上进行了尝试,但无法重现该错误,并且似乎可以正常工作.同样,在具有Android 5.1.1的关系播放器上,它似乎可以正常运行. 因此,这实际上是Moto G的问题,或者-我认为更可能是-Android 5.0.2的一个错误,该错误已在更高版本中得到解决.

I tried it on a Nexus 9 tablet running Android 6.0, there I could not reproduce the error and it seems to work. Also on a nexus player with Android 5.1.1 it seems to run without problems. So either it is really an issue of the Moto G or - what I think is more likely - a bug of Android 5.0.2 that was solved in later versions.

这篇关于蓝牙LE广告周期性地启动和停止时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆