When I connect a new device the bonding process starts and completes correctly. I am able to read and write all the characteristics without any problem. I can even bond another device and also works perfectly, but when I try to connect the first device, which is already bonded, the connection is rejected with a 531 error code (disconnected by user) on the ESP32 side.
The NimBLE configuration structure looks like this:
Code: Select all
ble_hs_cfg.reset_cb = ble_onResetCallback;
ble_hs_cfg.sync_cb = ble_onSyncCallback;
ble_hs_cfg.gatts_register_cb = ble_serviceRegisterCallback;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
ble_hs_cfg.sm_io_cap = BLE_HS_IO_DISPLAY_ONLY;
ble_hs_cfg.sm_sc = true;
ble_hs_cfg.sm_bonding = true;
ble_hs_cfg.sm_mitm = true;
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
Code: Select all
/* Configure RPA and random BLE address */
ble_hs_pvcy_rpa_config(NIMBLE_HOST_ENABLE_RPA);
ownAddrType = BLE_OWN_ADDR_RANDOM;
/* Begin advertising. */
ble_startAdvertising();