通过蓝牙LE在iOS和Android之间进行通信 [英] Communicating between iOS and Android with Bluetooth LE

查看:165
本文介绍了通过蓝牙LE在iOS和Android之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用CoreBluetooth的应用程序在iPad(中央)和iPhone(外围设备)之间进行通信。我有一项服务有两个特点。我有一台运行最新Android 4.3并支持BTLE的Nexus 7。 Android有点迟到了BTLE的潮流,但看起来他们正在接近它,就像iOS的做法一样,最初他们只支持扮演外围模式的核心版本。我可以加载示例Android BTLE应用程序并浏览附近的外围设备。通过我的iPhone广告作为外围设备,我可以在Android端附近的外围设备列表中看到CBAdvertisementDataLocalNameKey的值。我可以连接到iPhone,蓝牙符号在连接时从浅灰色变为黑色。连接始终持续10秒,然后断开连接。在Android方面,我应该会在连接时看到可用服务和特征列表。我已经证明Android代码设置正确,因为我可以将它连接到我拥有的TI CC2541DK-SENSOR硬件,并在连接时列出所有服务和特性。

I've got a working app using CoreBluetooth to communicate between an iPad (central) and iPhone (peripheral). I have one service that has two characteristics. I have a Nexus 7 running the latest Android 4.3 with BTLE support. Android is a bit late to jump on the BTLE bandwagon but it appears they are approaching it similarly to how iOS did, where initially they only support acting as a central with the peripheral mode coming in a later version. I can load the sample Android BTLE app and browse for nearby peripherals. With my iPhone advertising as a peripheral I can see the value from CBAdvertisementDataLocalNameKey in the list of nearby peripherals on the Android side. I can connect to the iPhone and the Bluetooth symbol turns from light gray to black when the connection is made. The connection always lasts exactly 10 seconds and then disconnects. On the Android side I'm supposed to see a list of available services and characteristics appear immediately upon connection. I've proved the Android code is setup correctly because I can connnect it to the TI CC2541DK-SENSOR hardware that I have and all services and characteristics are listed upon connecting to it.

我花了几天的时间来解决这个问题但没有成功。问题是我无法确定哪个设备出现错误并因此导致断开连接。在连接阶段或服务发现阶段,没有来自CBPeripheralManagerDelegate的回调,所以我不知道错误发生在什么时候(如果错误发生在iOS端)。在Android方面,调用一个方法来启动服务发现,但是从不调用它们的回调onServicesDiscovered,这是令人困惑的。有什么方法可以深入了解iOS端BTLE通信的内容,看看发生了什么,并确定发生了什么错误?

I've spent the last few days troubleshooting the issue with no success. The problem is I can't determine which device is experiencing an error and thus causing the disconnection. There are no callbacks from CBPeripheralManagerDelegate during the connection phase or service discovery phase so I have no idea at what point an error occurs (if the error is on the iOS side). On the Android side a method is called to initiate service discovery however their callback "onServicesDiscovered" is never called which is perplexing. Is there any way I can dig into the guts of the BTLE communication on the iOS side to see what's going on and determine what error is taking place?

推荐答案

我已经经历过至少一个星期这个同样的问题了。我已经在这里问了一个问题,我已经自己回答了。主要问题是Android BUG问题。它在固定的L2CAP channnel上发送一个非允许的命令。

I've already gone through this for at least one week having this same issue. I've already asked a question here and I've already answered on my own. The main problem is an Android BUG issue. It's sending a non permitted command on a fixed L2CAP channnel.

但是当Android与普通的外围BLE设备通信时,它的效果非常好。事实上,BLE样本就像一个魅力。问题是当与iOS设备通信时,例如:在建立连接之后,他们开始协商他们的连接参数(这个阶段不会发生在正常的BLE外设上),这就是问题出现的时候。 Android向iOS发送错误命令,iOS断开连接。这基本上就是它的工作方式

But when Android is communicating with normal peripheral BLE devices, it works pretty well. In fact, the BLE sample works like a charm. The problem is when is comunicating with an iOS device for example: Just after the connection is made, they start negotiating their connection parameters (this phase doesn't happen with normal BLE peripheral), and this is when the problem comes up. Android sends a bad command to iOS, iOS drops the connection. That's basically how it works

已经向Google报告了一些问题,其中一个问题已经被接受,我希望他们很快就会开始研究。

Some issues have been already reported to Google, and one of them have been already accepted and I hope they will start working on it soon.

不幸的是,你可以做的是等到下一个Android版本。无论如何,如果你想对这个问题有所了解,我强烈建议你查看我的问题报告以及我的所有测试文件。

Unfortunately, what you can do, is to wait until next Android release. Anyway, I highly suggest you to have a look at my issue report with all my test documents if you want to make some light on this problem.

这是链接:< a href =https://code.google.com/p/android/issues/detail?id=58725> https://code.google.com/p/android/issues/detail?id=58725

这篇关于通过蓝牙LE在iOS和Android之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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