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

天大地大妈咪最大 提交于 2019-12-19 04:46:45

问题


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

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

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).

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).

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

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

thank you lots.


回答1:


I just now faced the same problems.

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

A workaround is to explicitely disable BR/EDR support in the advertisements.

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

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.

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

Starting the bluez btgatt-server example:

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


来源:https://stackoverflow.com/questions/27552644/bluetooth-low-energy-android-gatt-client-connect-to-linux-gatt-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!