esp32s3 pair / reconnect / reboot behavior

mps360
Posts: 7
Joined: Mon Oct 16, 2023 8:32 pm

esp32s3 pair / reconnect / reboot behavior

Postby mps360 » Mon Nov 06, 2023 4:21 pm

Hi!
I'm using a mostly un modified 'gatt_security_server'.
I added a print on reboot to show bonded devices.

This particular example does not seem to be seeing ESP_GAP_BLE_AUTH_CMPL_EVT when I connect using the nordic nRF connect utility from my phone. Oddly, I can write to UUID 1A37 after the key exchange. I've highlit that in the code below.

I have my own application based on a BLE HID example that is seeing ESP_GAP_BLE_AUTH_CMPL_EVT, but the bonding/pairing information does not seem to persist in either project.

My goal is to pair/bond a device, and
- disconnect/reconnect from the host/central without pairing again
- allow the device to reboot, and allow the host/central to connect without pairing again
- allow the device to power cycle, and allow the host/central to connect without pairing again

Other than the gatt secure server walk through, are there some docs that I'm missing related to this?
Where is the whitelist documented? Should I be using that?

I have no IOCAP - no display, no input.
I've tried ESP_LE_AUTH_BOND, and ESP_LE_AUTH_REQ_SC_BOND with different failures on reconnect

Here are some logs of what I'm seeing

I (296) cpu_start: Pro cpu up.
I (296) cpu_start: Starting app cpu, entry point is 0x40375334
0x40375334: call_start_cpu1 at /Users/mike/esp/esp-idf/components/esp_system/port/cpu_start.c:141

I (0) cpu_start: App cpu up.
I (311) cpu_start: Pro cpu start user code
I (311) cpu_start: cpu freq: 160000000 Hz
I (311) cpu_start: Application information:
I (314) cpu_start: Project name: sec_gatts_demo
I (320) cpu_start: App version: 1
I (324) cpu_start: Compile time: Nov 5 2023 12:26:25
I (330) cpu_start: ELF file SHA256: 58fea8d1e07faff5...
I (336) cpu_start: ESP-IDF: v5.0.2-dirty
I (342) cpu_start: Min chip rev: v0.0
I (347) cpu_start: Max chip rev: v0.99
I (351) cpu_start: Chip rev: v0.1
I (356) heap_init: Initializing. RAM available for dynamic allocation:
I (363) heap_init: At 3FC9D8C0 len 0004BE50 (303 KiB): DRAM
I (370) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (376) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (382) heap_init: At 600FE010 len 00001FF0 (7 KiB): RTCRAM
I (390) spi_flash: detected chip: mxic
W (393) spi_flash: Detected flash size > 16 MB, but access beyond 16 MB is not supported for this flash model yet.
I (404) spi_flash: flash io: dio
W (408) spi_flash: Detected size(32768k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (422) coexist: coexist rom version e7ae62f
I (427) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (467) BT_INIT: BT controller compile version [80abacd]
I (467) phy_init: phy_version 540,a5d905b,Oct 20 2022,19:36:11
W (467) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (507) system_api: Base MAC address is not set
I (517) system_api: read default base MAC address from EFUSE
I (517) BT_INIT: Bluetooth MAC: 68:b6:b3:3e:89:42

I (517) SEC_GATTS_DEMO: app_main init bluetooth
I (567) SEC_GATTS_DEMO: The number handle = 8
I (577) SEC_GATTS_DEMO: advertising start success
I (577) SEC_GATTS_DEMO: Bonded devices number : 0

I (577) SEC_GATTS_DEMO: Bonded devices list : 0

I (89207) SEC_GATTS_DEMO: ESP_GATTS_CONNECT_EVT
W (91967) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK
I (92097) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LENC
I (92097) SEC_GATTS_DEMO: key type = ESP_LE_KEY_PENC
I (92097) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LID
E (95567) BT_BTM: Device not found

W (95577) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
I (95577) SEC_GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (95587) SEC_GATTS_DEMO: remote BD_ADDR: 60f8ee78afc8
I (95587) SEC_GATTS_DEMO: address type = 1
I (95587) SEC_GATTS_DEMO: pair status = fail
I (95597) SEC_GATTS_DEMO: fail reason = 0x66
I (95597) SEC_GATTS_DEMO: Bonded devices number : 0

I (95607) SEC_GATTS_DEMO: Bonded devices list : 0

I (95617) SEC_GATTS_DEMO: advertising start success
I (99137) SEC_GATTS_DEMO: ESP_GATTS_CONNECT_EVT
W (101087) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK
I (101217) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LENC
I (101217) SEC_GATTS_DEMO: key type = ESP_LE_KEY_PENC
I (101217) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LID
E (102647) BT_BTM: Device not found

W (102657) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
I (102657) SEC_GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (102667) SEC_GATTS_DEMO: remote BD_ADDR: 60f8ee78afc8
I (102667) SEC_GATTS_DEMO: address type = 1
I (102667) SEC_GATTS_DEMO: pair status = fail
I (102677) SEC_GATTS_DEMO: fail reason = 0x66
I (102677) SEC_GATTS_DEMO: Bonded devices number : 0

I (102687) SEC_GATTS_DEMO: Bonded devices list : 0

I (102697) SEC_GATTS_DEMO: advertising start success
I (110867) SEC_GATTS_DEMO: ESP_GATTS_CONNECT_EVT
W (114257) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK
I (114387) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LENC
I (114387) SEC_GATTS_DEMO: key type = ESP_LE_KEY_PENC
I (114387) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LID
I (122667) SEC_GATTS_DEMO: ESP_GATTS_WRITE_EVT, write value:
I (122667) SEC_GATTS_DEMO: 01 00
I (123327) SEC_GATTS_DEMO: ESP_GATTS_WRITE_EVT, write value:
I (123327) SEC_GATTS_DEMO: 00 00
E (126467) BT_BTM: Device not found

W (126477) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
I (126477) SEC_GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13

I (126487) SEC_GATTS_DEMO: remote BD_ADDR: 60f8ee78afc8
I (126487) SEC_GATTS_DEMO: address type = 1
I (126487) SEC_GATTS_DEMO: pair status = fail
I (126497) SEC_GATTS_DEMO: fail reason = 0x66
I (126497) SEC_GATTS_DEMO: Bonded devices number : 0

I (126507) SEC_GATTS_DEMO: Bonded devices list : 0

I (126517) SEC_GATTS_DEMO: advertising start success
I (128417) SEC_GATTS_DEMO: ESP_GATTS_CONNECT_EVT
W (130397) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK
I (130527) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LENC
I (130527) SEC_GATTS_DEMO: key type = ESP_LE_KEY_PENC
I (130527) SEC_GATTS_DEMO: key type = ESP_LE_KEY_LID
I (134247) SEC_GATTS_DEMO: ESP_GATTS_WRITE_EVT, write value:
I (134247) SEC_GATTS_DEMO: 01 00
I (135027) SEC_GATTS_DEMO: ESP_GATTS_WRITE_EVT, write value:
I (135027) SEC_GATTS_DEMO: 00 00
E (137007) BT_BTM: Device not found

W (137007) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
I (137007) SEC_GATTS_DEMO: ESP_GATTS_DISCONNECT_EVT, disconnect reason 0x13
I (137017) SEC_GATTS_DEMO: remote BD_ADDR: 60f8ee78afc8
I (137017) SEC_GATTS_DEMO: address type = 1
I (137017) SEC_GATTS_DEMO: pair status = fail
I (137027) SEC_GATTS_DEMO: fail reason = 0x66
I (137027) SEC_GATTS_DEMO: Bonded devices number : 0

I (137037) SEC_GATTS_DEMO: Bonded devices list : 0

I (137047) SEC_GATTS_DEMO: advertising start success

mps360
Posts: 7
Joined: Mon Oct 16, 2023 8:32 pm

Re: esp32s3 pair / reconnect / reboot behavior

Postby mps360 » Thu Nov 09, 2023 7:08 pm

Tried the same work flow with IDF example esp_hid_device.
Are there any examples, either insecure or secure, that deal with pair and reboot more gracefully?

- Device boots and advertises
- iPhone connects to device
- Paired with code that matches console log
- Reboot device, it advertises
- iPhone unable to reconnect

I (523) BT_INIT: Bluetooth MAC: 68:b6:b3:3e:c0:8a

W (573) BT_BTM: BTM_BleWriteAdvData, Partial data write into ADV
I (573) HID_DEV_DEMO: setting ble device
I (583) HID_DEV_BLE: START
I (1773) HID_DEV_BLE: CONNECT
I (1783) HID_DEV_DEMO: Send the volume
E (1783) BLE_HIDD: Indicate Not Enabled: 0
E (1883) BLE_HIDD: Indicate Not Enabled: 0
E (2193) BT_BTM: Device not found
W (2193) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
I (2203) HID_DEV_BLE: DISCONNECT: TERMINATE_PEER_USER
E (2203) ESP_HID_GAP: BLE GAP AUTH ERROR: 0x66

mps360
Posts: 7
Joined: Mon Oct 16, 2023 8:32 pm

Re: esp32s3 pair / reconnect / reboot behavior

Postby mps360 » Thu Nov 09, 2023 10:56 pm

I'm noticing that reconnecting with NimBLE is painless with the 'bleperiph' example.
My project is using bluedroid.

Who is online

Users browsing this forum: No registered users and 52 guests