Pairing and unBonding nrf52840 dk Central

Hi, 

I am currently trying to work with pairing and bonding between the peripheral and Central device.

I am using two nrf52840 dk one as central and the other as peripheral. I am able to pair and bond with the device using the passkey entry. I used this Example to code my peripheral device

Pairing process - Nordic Developer Academy exercise 2. And used central_Uart code to program my central device with modifications done to enter passkey value. 

Everything seems to be working, just the way it works when I use the NRF connect app to connect to my peripheral device.

I am using the un-bonding code after the BLE initialization stage, (to mimic the forget device part when using the app after the bond is deleted from the peripheral device), so every time I reset my central device old pairing information is deleted and a new bond is created. 

err = bt_unpair(BT_ID_DEFAULT,NULL);

    if(err){
        printk("failed");
    }else{
        printk("bond deleted");
    }
My question is when the peripheral deletes the bond and the central tries to connect to the peripheral without resetting, it doesn't pair as it's still using the old pairing information to create the bond.
1. How do I delete the old pairing information from the central side to re-pair without resetting my central device?
2. How do I know when the bond was deleted on the peripheral device?
Basically, I want to implement the "peer pairing information not found" logic used on the NRF app on my central device. With the way I have got it to work I delete the bonds whenever the central is reset. 

I tried to use the unpair code within the auth_cancel or pairing failed callbacks, but the callbacks don't get triggered even after I call this multiple times,

            err = bt_conn_set_security(conn, BT_SECURITY_L2);
            if (err) {
                printk("Failed to set security: %d\n", err);

                gatt_discover(conn);
            }else{
                printk("security set\n");
                printk("set level: %d\n",bt_conn_get_security(conn));
             
            }
Can you please advise on how I can do this? 
Thanks, 
Mujeefa 
Parents
  • HI Mujeefa,

    1. How do I delete the old pairing information from the central side to re-pair without resetting my central device?

    You can iterate through all bonds using bt_foreach_bond() and call bt_unpair() to delete them (or just the one you want to delete if you have others. you want to keep).

    You can also alow re-pairing using:

    CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y
    CONFIG_BT_ID_UNPAIR_MATCHING_BONDS=y

    2. How do I know when the bond was deleted on the peripheral device?

    You will get the security_changed callback regardless of if securing the link was successfull or not, and if it was not (for instance due to the peer not having the bondign information anymore, you will know. See and example of that here.

Reply
  • HI Mujeefa,

    1. How do I delete the old pairing information from the central side to re-pair without resetting my central device?

    You can iterate through all bonds using bt_foreach_bond() and call bt_unpair() to delete them (or just the one you want to delete if you have others. you want to keep).

    You can also alow re-pairing using:

    CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y
    CONFIG_BT_ID_UNPAIR_MATCHING_BONDS=y

    2. How do I know when the bond was deleted on the peripheral device?

    You will get the security_changed callback regardless of if securing the link was successfull or not, and if it was not (for instance due to the peer not having the bondign information anymore, you will know. See and example of that here.

Children
No Data
Related