What is the correct way to enter pairing mode on an ESP32 peripheral device with only a single button?
I want the device to allow pairing and bonding after a button press. Then, after the device reboots only a previous paired/bonded device will be allowed to connect.
I have seen this question asked before and here are the things I tried (unsuccessfully).
1. Whitelisting
- In "pairing mode" change the
Code: Select all
adv_filter_policy--> ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY.
- After a successful pair and bonding, add the device to the whitelist
- Set the (so only whitelisted devices can connect).
Code: Select all
adv_filter_policy--> ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST
Result: After step (c) the whitelisted device still cannot connect. It seems like the device wasn't added to the whitelist because it cannot connect. However, I have checked the count of whitelisted devices (using function: esp_ble_gap_get_whitelist_size ) and it says the count went up by one. Similarly, GAP event ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT also shows a successful "add" operation. (Side note: param->update_whitelist_cmpl.wl_opration. "wl_opration" is spelled wrong).
Question: Is there a way to print out the whitelist device addresses? Or debug it in some way?
2. Second approach: Toggle IO_CAP after pairing/bonding.
- Enter pairing mode by setting
Code: Select all
esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
- Pair and bond with the device
- Stop allowing "bonding" by setting:
Code: Select all
esp_ble_io_cap_t iocap = ESP_IO_CAP_IN; esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
Question: Is there a way to change the IO capability and have previously paired / bonded devices skip the pairing process after the change?
Notes:
- I'm using IDF esp-idf-v4.2.1/
- I'm using an Android smartphone to connect to the ESP32 WROOM board
- This is all using BLE with ESP_BLE_SM_AUTHEN_REQ_MODE --> ESP_LE_AUTH_REQ_SC_BOND
Thanks for your help!