How to make Android BLE connect to Bluez Periphera

2019-06-05 16:58发布

问题:

I am trying to connect my Nexus 5 (Android 6.0.1) smartphone to my desktop computer (Ubuntu 15.04 64-bit with BlueZ 5.36) using Bluetooth Low Energy. I use a BT 4.0 USB dongle with a CSR BC8510 chipset.

The setup did actually work just a couple of days ago. Then I switched to a Broadcom USB dongle and it started to become unstable. Connecting became slow and started to fail. It now does not work anymore at all even though I switched back to the CSR dongle and a different Ubuntu machine (still using the same Android device). However receiving advertising packets was not affected and does still work. My Project was using the Android Beacon Library and continuously scanned for BLE advertising packets.

A minimal setup that does not work for me --but should in my opinion-- is the following:

Make BlueZ advertise using the following script:

# Set advertising data (AltBeacon format).
sudo hcitool -i hci0 cmd 0x08 0x0008 1F 02 01 02 1B FF 00 00 BE AC 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 BC 00

# Set advertising interval.
sudo hcitool -i hci0 cmd 0x08 0x0006 A0 00 A0 00 00 00 00 00 00 00 00 00 00 07 00

# Start advertising.
sudo hcitool -i hci0 cmd 0x08 0x000a 01

# Run Bluez example gatt server.
./test/example-gatt-server

Start a BLE scanner, for example this one. It receives the advertising packets and lists the peripheral but trying to connect fails.

So far I tried

  • different BlueZ versions
  • different Linux machines
  • different BLE scanner apps from the Google Play Store
  • unplugging and replugging the dongle
  • rebooting both Ubuntu and Android
  • resetting network settings and even factory resetting Android

Using the BlueZ btmon tool I see no HCI traffic when trying to connect. That makes me guess the problem is somewhere in my BlueZ HCI configuration or inside Android or my Android hardware. I did not yet try a different Android device but I will do so as soon as possible.

Did anyone have similar issues or know how to debug at a deeper level? Thank you very much.

回答1:

Did you get luck to solve this problem? I think connection parameters ( not possible from userspace bluez so far) if configured, should be able to solve the problem. I could see with bluez, android app disconnects immediately when making connection with GATT.



回答2:

I am having a similar problem. Here is the progress I've made

Make sure Android is configured to connect only in BLE mode:

mBluetoothGatt = device.connectGatt(this, false, mGattCallback, TRANSPORT_LE);

Try connecting from a non-Android device first (this is the part I'm stuck on)