BLE: Recipe for handling BLE pairing with ESP32 acting as a peripheral

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

BLE: Recipe for handling BLE pairing with ESP32 acting as a peripheral

Postby kolban » Thu Jun 29, 2017 3:50 am

I'm studying how to make the BLE be a peripheral to controllers. I'm testing with Android phones and a Chrome book. I have placed my ESP32 into a BLE advertising state and the controller devices seem to be able to see the ESP32 (BLE) device just fine. When I try and pair, I see the following events occur at the ESP32 (BLE) end:

ESP_GATTS_CONNECT_EVT
ESP_GAP_BLE_SEC_REQ_EVT
-> I response with a call to esp_ble_gap_security_rsp() with accept=true

On my devices, I see a message asking if I "see" a passkey on my peripheral?

40 seconds later I see (on the ESP32 BLE side) a:
ESP_GAP_BLE_AUTH_CMPL_EVT with decoded information:

[bd_addr: 60:93:99:c5:61:da, key_present: 0, key: ***, key_type: 0, success: 0, fail_reason: 99, addr_type: ***, dev_type: ESP_BT_DEVICE_TYPE_BLE]

My mystery is to understand this protocol flow. I initiate the pairing from the controller, the ESP32 (BLE) then receives the events described above ... but it seems that my ESP32 (BLE) is missing a step ... it is almost as though the ESP32 is supposed to respond when it receives a ESP_GAP_BLE_SEC_REQ_EVT ... unfortunately I don't know what that might be.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Island
Posts: 36
Joined: Thu Jun 29, 2017 7:20 am

Re: BLE: Recipe for handling BLE pairing with ESP32 acting as a peripheral

Postby ESP_Island » Thu Jun 29, 2017 10:04 am

Because in ESP32, IO capability is set to “Keyboard and Display” by default. So in your case of paring, smart phone acts as keyboard role (need to input passkey) and ESP32 acts as Display role (generate a random passkey and display in the screen). The passkey is received in the GAP event ESP_GAP_BLE_PASSKEY_NOTIF_EVT and you can printf the passkey if you don’t have the screen in your dev board.

Please refer to example “gatt_security_server” (IDF 2.1) to know more about security pairing configurations, You can also find the details about SMP legacy pairing in Bluetooth Spec V5.0 (Vol3, Part H).

Duracell
Posts: 5
Joined: Sun Oct 08, 2017 7:39 am

Re: BLE: Recipe for handling BLE pairing with ESP32 acting as a peripheral

Postby Duracell » Thu Oct 12, 2017 2:38 pm

Hi

Did you have success with the ESP_IO_CAP_KBDISP numeric comparison method for pairing?

Thanks

Dura

Who is online

Users browsing this forum: No registered users and 135 guests