Bluetooth LE: Unable to connect Andorid >= 5.0 to ESP32 GATT server

michaelwgnr
Posts: 22
Joined: Wed Dec 21, 2016 3:41 pm

Bluetooth LE: Unable to connect Andorid >= 5.0 to ESP32 GATT server

Postby michaelwgnr » Fri Jan 06, 2017 12:11 pm

I decided to create a seperate topic for this issue, that I originally mentioned in my UUID-not-advertised-topic. For better visibility and clearer structure.

For some reason, most of the time I'm not able to connect to the ESP32 GATT server demo (example 14) using the Android app "BLE Scanner", while on iOS with "LightBlue", connection seems to work without any problems. User mephistod2 found out, that a connection to Android 4.4 seems to work, which I was able to verify.

Looking at the logs of an Andorid 6.0 phone (Sony Xperia Z5 Compact), the connection attempt looks like in the following listing (timestamp of disconnection is 01-06 10:45:28.531). Note, that on an Android 7.0 device (Motorola Nexus 6) it looks more or less the same.

Code: Select all

01-06 10:45:23.381  2521  5693 D BluetoothGatt: connect() - device: 24:0A:C4:00:1F:24, auto: false
01-06 10:45:23.381  2521  5693 D BluetoothGatt: registerApp()
01-06 10:45:23.381  2521  5693 D BluetoothGatt: registerApp() - UUID=3fc70ab5-ae10-45f8-8f2c-e4f26b349286
01-06 10:45:23.385  4293  4589 D BtGatt.GattService: registerClient() - UUID=3fc70ab5-ae10-45f8-8f2c-e4f26b349286
01-06 10:45:23.386  4293  4376 D BtGatt.GattService: onClientRegistered() - UUID=3fc70ab5-ae10-45f8-8f2c-e4f26b349286, clientIf=5
01-06 10:45:23.387  2521  2562 D BluetoothGatt: onClientRegistered() - status=0 clientIf=5
01-06 10:45:23.387  4293  4312 D A2dpService: getA2DPService(): returning com.android.bluetooth.a2dp.A2dpService@4978e40
01-06 10:45:23.388  4293  4312 I A2dpService: audio isMusicActive is false
01-06 10:45:23.389  4293  4312 D BtGatt.GattService: clientConnect() - address=24:0A:C4:00:1F:24, isDirect=true
01-06 10:45:23.390  4293  4376 D bt_btif_config: btif_get_address_type: Device [24:0a:c4:00:1f:24] address type 0
01-06 10:45:23.390  4293  4376 D bt_btif_config: btif_get_device_type: Device [24:0a:c4:00:1f:24] type 3
01-06 10:45:23.390  4293  4454 W bt_l2cap: L2CA_ErtmConnectReq()  PSM: 0x001f  BDA: 240ac4001f24  p_ertm_info: 0x00000000 allowed:0x0 preferred:0
01-06 10:45:28.530  4293  4454 W bt_l2cap: L2CAP - st: CLOSED evt: 1
01-06 10:45:28.531  4293  4454 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0004
01-06 10:45:28.531  4293  4454 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0004
01-06 10:45:28.531  4293  4454 W bt_btif : bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0004
01-06 10:45:28.531  4293  4376 D BtGatt.GattService: onConnected() - clientIf=5, connId=0, address=24:0A:C4:00:1F:24
01-06 10:45:28.532  2521  2531 D BluetoothGatt: onClientConnectionState() - status=133 clientIf=5 device=24:0A:C4:00:1F:24
01-06 10:45:28.532  2521  2531 E c       : Disconnected
01-06 10:45:28.533  2521  2531 D BluetoothGatt: refresh() - device: 24:0A:C4:00:1F:24
01-06 10:45:28.536  4293  4319 D BtGatt.GattService: refreshDevice() - address=24:0A:C4:00:1F:24
01-06 10:45:28.537  2521  2531 D BluetoothGatt: close()
01-06 10:45:28.537  2521  2531 D BluetoothGatt: unregisterApp() - mClientIf=5
01-06 10:45:28.538  4293  4593 D BtGatt.GattService: unregisterClient() - clientIf=5


Now, I noticed pull request #190 "BLE Advertisement flags not working" on github, where [github-]user inwotep refered to this also solving the Android connection problem. So, I applied his changes and ran the GATT server example with these incorporated, but this seemed to not change the outcome.

At some point, for some reason the connection with Android > 5.0 seemed to work sometimes. Unfortunately, I can't reproduce this currently and I'm not entirely sure what code exactly ran on the ESP32 when it did. But when it did, as soon as I tried to read or write a characteristic, the ESP32 crashed with the following dump:

Code: Select all

E (87702) BT: command_timed_out hci layer timeout waiting for response to a command. opcode: 0x41d
Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0)
Register dump:
PC      : 0x40085074  PS      : 0x00060034  A0      : 0x80083012  A1      : 0x3ffcf360
A2      : 0x3ffceed4  A3      : 0x00060023  A4      : 0x00060020  A5      : 0x3ffd0480
A6      : 0x00000003  A7      : 0x00060e23  A8      : 0xb33f0000  A9      : 0xb33fffff
A10     : 0x00060023  A11     : 0x00000000  A12     : 0x0000006e  A13     : 0xb33f0000
A14     : 0xb33fffff  A15     : 0x00000005  SAR     : 0x00000004  EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffb

Backtrace: 0x40085074:0x3ffcf360 0x40083012:0x3ffcf380 0x40084817:0x3ffcf3a0 0x4008516c:0x3ffcf3e0 0x40085186:0x3ffcf420

Rebooting...


Looking at the backtrace with the map file at hand (unfortunately don't have a debugger so far), the 0x3ff... addresses seem to point to memory addresses or RO-memory addresses(?) and the 0x400... addresses are FreeRTOS functions. The Opcode 0x41D in the command timed out error at the top seems to refer to HCI_READ_RMT_VERSION_INFO if I'm not mistaken. The crash always happens with this OPcode.

So in conclusion:
  1. Most of the time, connecting to the GATTS demo with Android >= 5.0 does not work
  2. In the rare cases it does work (which I unforunately cannot reproduce right now), the ESP32 crashes with the dump posted above.

(note: while I was compiling all the information for this post, I realised that some updates to the BLE stack have been committed in the meantime, including an equivalent to the above mentioned fix in pull request #190. The Android problem still persists, though!)

michaelwgnr
Posts: 22
Joined: Wed Dec 21, 2016 3:41 pm

Re: Bluetooth LE: Unable to connect Andorid >= 5.0 to ESP32 GATT server

Postby michaelwgnr » Wed Jan 18, 2017 7:04 am

Any news on this?

anakinsw
Posts: 1
Joined: Mon Jan 23, 2017 7:22 pm

Re: Bluetooth LE: Unable to connect Andorid >= 5.0 to ESP32 GATT server

Postby anakinsw » Mon Jan 23, 2017 8:08 pm

Hi michaelwgnr!


If you modify the p_service_uuid parameter to NULL, it works. I know that is not the best solution but to try and play ....

Code: Select all

static esp_ble_adv_data_t test_adv_data = {
    .set_scan_rsp = false,
    .include_name = true,
    .include_txpower = true,
    .min_interval = 0x20,
    .max_interval = 0x40,
    .appearance = 0x00,
    .manufacturer_len = 0, //TEST_MANUFACTURER_DATA_LEN,
    .p_manufacturer_data =  NULL, //&test_manufacturer[0],
    .service_data_len = 0,
    .p_service_data = NULL,
    .service_uuid_len = 32,
    .p_service_uuid = NULL, //test_service_uuid128, (for Android devices patch)
    //.flag = 0x6, //02 no conectable,06 conectable
    .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
};

HITMAnsOFT
Posts: 9
Joined: Fri May 05, 2017 6:53 pm

Re: Bluetooth LE: Unable to connect Andorid >= 5.0 to ESP32 GATT server

Postby HITMAnsOFT » Sat May 06, 2017 5:59 pm

anakinsw wrote:Hi michaelwgnr!


If you modify the p_service_uuid parameter to NULL, it works. I know that is not the best solution but to try and play ....


I'm having the same problem, but this workaround doesn't help. Android version is 6.0.1. Another 4.4.4 device can discover services successfully.

HITMAnsOFT
Posts: 9
Joined: Fri May 05, 2017 6:53 pm

Re: Bluetooth LE: Unable to connect Andorid >= 5.0 to ESP32 GATT server

Postby HITMAnsOFT » Wed Jun 07, 2017 11:58 am

Hi michaelwgnr,

were you able to resolve this issue?

Who is online

Users browsing this forum: No registered users and 2 guests