低功耗蓝牙:Android Gatt客户端连接到Linux Gatt Server [英] Bluetooth Low Energy : Android Gatt-Client connect to Linux Gatt Server

查看:931
本文介绍了低功耗蓝牙:Android Gatt客户端连接到Linux Gatt Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过蓝牙低功耗GATT模式将android连接到linux.

I try to connect android to linux via bluetooth low energy GATT mode.

Bluez中有一个示例代码: btgatt-server.c ,我将其用作服务器.

There is a example code in Bluez: btgatt-server.c, I use it as server.

Android端作为 Android官方示例:连接到GATT服务器.也就是说,使用函数BluetoothDevice :: connectGatt(上下文上下文,布尔自动连接,BluetoothGattCallback回调).

The Android Side be as the Android official example:Connecting to a GATT Server. That is, use function BluetoothDevice::connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback).

运行后,Android部分返回连接成功,(BluetoothGattCallback :: onConnectionStateChange的参数为STATE_CONNECTED),但是linux(btgatt-server)中的程序未得到任何响应,仍在等待接受中阻塞. (第485行).

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. ( line 485).

我还使用了另一个示例代码: l2cap-ble.c ,结果完全一样.

I also used another example code : l2cap-ble.c, the result was totally the same.

有人可以帮助我吗?我的目标是:连接后,Linux gatt服务器将向Android发送数据.然后断开连接.

Anyone could help me? my goal is : after connecting, linux gatt server would send a data to Android. Then disconnecting.

非常感谢.

推荐答案

我刚才也遇到了同样的问题.

I just now faced the same problems.

这似乎是Android和Broadcom蓝牙模块发生的错误. Android会以某种方式连接到错误的l2cap频道.

This seems like a bug that happens with Android and Broadcom bluetooth modules. Android somehow connects to the wrong l2cap channel.

一种解决方法是明确禁用广告中的BR/EDR 支持.

可以找到

The bug report on google with the solution in #8 can be found here, the quote on the hint that helped me:

我从Broadcom获得了有关此错误的信息,但我认为这并不是他们的错误.如果未在广告中专门设置不支持BR/EDR"位(第2位),则Broadcom堆栈将使用BR/EDR和BTLE. 将领先的广告包装从020102更改为020106解决了该问题.

I have obtained information from Broadcom regarding this bug and I don't think its a bug on their part. 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. Changing the leading advertisement package from 020102 to 020106 solved the problem.

使用bluez btmgmt 在设备hci0上配置广告,我发出以下命令:

Using bluez btmgmt for configuring the advertisements on device hci0 i issue the following commands:

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

以bluez btgatt服务器示例为例:

Starting the bluez btgatt-server example:

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

这篇关于低功耗蓝牙:Android Gatt客户端连接到Linux Gatt Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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