Pairing or bonding from ESP32 Central using NimBLE stack

ESP_Prasad
Posts: 18
Joined: Tue Nov 12, 2019 7:46 am

Re: Pairing or bonding from ESP32 Central using NimBLE stack

Postby ESP_Prasad » Fri May 01, 2020 8:05 am

Hi @nirmal.lad, It seems I referred to some other log and made that last comment. Sorry for that, please disregard my earlier comment. Can you please provide complete logs after `make erase_flash flash monitor` again ? I could only think of reason for this error might be because you are switching off/on your phone's Bluetooth as well before reconnecting to ESP32. Can you try without changing the Bluetooth state of phone (no reboot & no turning off Bluetooth once bond is created) ? The reason is, from the Bluetooth spec (Vol 6, Part B, section 1.3.2.1) :
If the static address of a device is changed, then the address stored in
peer devices will not be valid and the ability to reconnect using the old address
will be lost.
If the `peer_id_addr` is changed then this is treated as a new device.

nirmal.lad
Posts: 7
Joined: Mon Apr 20, 2020 5:33 am

Re: Pairing or bonding from ESP32 Central using NimBLE stack

Postby nirmal.lad » Fri May 01, 2020 9:56 am

Hello @ESP_Prasad,

Please find the attached log file.
I have not restarted or closed BLE in mobile phone.
Please check the attached logs.
After pairing and communication done and then rebooting ESP32, the device reconnects to Mobile phone.
This time encryption change is not generated. So ESP32 doesn't attempt for R/W data on characteristics.
and Disconnects afters few seconds.

Looking forward to your response.
Attachments
ble_logs_01052020.txt
(122.47 KiB) Downloaded 512 times

ESP_Prasad
Posts: 18
Joined: Tue Nov 12, 2019 7:46 am

Re: Pairing or bonding from ESP32 Central using NimBLE stack

Postby ESP_Prasad » Mon May 04, 2020 5:51 pm

Hi @nirmal.lad,

I could see the encryption state changed to encrypted in your logs

Code: Select all

Encrypt change: status=0 handle=0 state=1
I don't see any issue with pairing/bonding from BLE central.

From the logs, I could see disconnection reason = 546, which is BLE_ERR_LMP_LL_RSP_TMO(LMP Response Timeout / LL Response Timeout). As you are using nRF app, you might be able to capture phone side (advertiser) logs with DEBUG verbosity. They can be helpful to debug this issue further.

nirmal.lad
Posts: 7
Joined: Mon Apr 20, 2020 5:33 am

Re: Pairing or bonding from ESP32 Central using NimBLE stack

Postby nirmal.lad » Wed May 06, 2020 2:08 pm

Hello @ESP_Prasad,

I have attached the log from both sides i.e. ESP logs as well as nrf Connect App log.
Can you tell me that, once bonding is done, how communication occurs?
Do I need to wait for encryption change event on re-connection after bonding?
Or there is some other methods to verify secure connection.

Looking forward to your response.
Attachments
nimBleerrlog_06052020_1921.txt
ESP Log
(72.46 KiB) Downloaded 528 times
nimBLELog 2020-05-06 19_20_37.txt
Nrf Connect App log
(7.64 KiB) Downloaded 518 times

ESP_Prasad
Posts: 18
Joined: Tue Nov 12, 2019 7:46 am

Re: Pairing or bonding from ESP32 Central using NimBLE stack

Postby ESP_Prasad » Mon May 11, 2020 11:33 am

Hi @nirmal.lad,

From logs, I do not see any obvious issue, except

Code: Select all

Disconnection Complete: status=0 handle=0 reason=8
disconnect; reason=520
The disconnection is happening because of supervision timeout or BLE_ERR_CONN_SPVN_TMO. Now in your application code, I do not see anything after service discovery completed callback blecent_on_disc_complete , which results in connection timeout error.
Can you tell me that, once bonding is done, how communication occurs?
There won't be much difference between communication methodology. Please refer to BLE specs or belprph demo example and try to build understanding around pairing/bonding/read/write/notify etc.
Do I need to wait for encryption change event on re-connection after bonding?
Or there is some other methods to verify secure connection.
I will try to answer the query in best possible manner, but let me know if you are looking for something else. If you are accessing (read/write) any characteristic which needs link to be encrypted (e.g. `BLE_GATT_CHR_F_READ_ENC` in bleprph example), then of course you need to wait for encryption change event. But again, this will be taken care by `ble_gap_security_initiate()`, once this function returns successfully you can run your application specific scenarios (read/write/notify).

If you are planning to use both peripheral and central then I would suggest to start with `bleprph` example as it will be more intuitive exercise. Once you understand how central connects/reads/writes to characteristics then you can proceed to building central example which will essentially do what you were doing manually through scanner (nRF app).

Who is online

Users browsing this forum: No registered users and 5 guests