简体   繁体   English

低功耗蓝牙:Android Gatt客户端连接到Linux Gatt Server

[英]Bluetooth Low Energy : Android Gatt-Client connect to Linux Gatt Server

I try to connect android to linux via bluetooth low energy GATT mode. 我尝试通过蓝牙低功耗GATT模式将android连接到linux。

There is a example code in Bluez: btgatt-server.c , I use it as server. Bluez中有一个示例代码: btgatt-server.c ,我将其用作服务器。

The Android Side be as the Android official example:Connecting to a GATT Server . Android Side作为Android官方示例:连接到GATT服务器 That is, use function BluetoothDevice::connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback). 也就是说,使用函数BluetoothDevice :: connectGatt(上下文上下文,布尔自动连接,BluetoothGattCallback回调)。

After running, the Android part returned the connection be successful,(the parameter of BluetoothGattCallback::onConnectionStateChange be STATE_CONNECTED), but the program in linux(btgatt-server) did not get any response, that still block in waiting accepting. 运行后,Android部分返回成功的连接(BluetoothGattCallback :: onConnectionStateChange的参数为STATE_CONNECTED),但是linux(btgatt-server)中的程序未获得任何响应,该响应仍在等待接受中。 ( line 485). (第485行)。

I also used another example code : l2cap-ble.c , the result was totally the same. 我还使用了另一个示例代码: l2cap-ble.c ,结果完全相同。

Anyone could help me? 有人可以帮助我吗? my goal is : after connecting, linux gatt server would send a data to Android. 我的目标是:连接后,Linux gatt服务器将向Android发送数据。 Then disconnecting. 然后断开连接。

thank you lots. 非常感谢。

I just now faced the same problems. 我刚才也面临同样的问题。

This seems like a bug that happens with Android and Broadcom bluetooth modules. 这似乎是Android和Broadcom蓝牙模块发生的错误。 Android somehow connects to the wrong l2cap channel. Android以某种方式连接到错误的l2cap频道。

A workaround is to explicitely disable BR/EDR support in the advertisements. 解决方法是在广告中明确禁用BR / EDR支持。

The bug report on google with the solution in #8 can be found here , the quote on the hint that helped me: 可以在这里找到有关#8解决方案的google上的错误报告,该提示对我有帮助:

I have obtained information from Broadcom regarding this bug and I don't think its a bug on their part. 我已经从Broadcom获得了有关此错误的信息,但我认为它们本身并不是错误。 If one does not specifically set the 'BR/EDR not supported' bit in the advertisement (bit 2), the Broadcom stack will use BR/EDR and BTLE. 如果未在广告中专门设置“不支持BR / EDR”位(第2位),则Broadcom堆栈将使用BR / EDR和BTLE。 Changing the leading advertisement package from 020102 to 020106 solved the problem. 将领先的广告包从020102更改为020106解决了该问题。

Using bluez btmgmt for configuring the advertisements on device hci0 i issue the following commands: 使用bluez btmgmt在设备hci0上配置广告,我发出以下命令:

btmgmt -i hci0 power off 
btmgmt -i hci0 le on
btmgmt -i hci0 connectable on
btmgmt -i hci0 bredr off        # Disables BR/EDR !
btmgmt -i hci0 advertising on
btmgmt -i hci0 power on

Starting the bluez btgatt-server example: 启动bluez btgatt服务器示例:

btgatt-server -i hci0 -s low -t public -r -v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM