This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to Delete Bonds when table full.

Hello, I am using the HTS example for the nrf51822.

In the example, bond information can be deleted during initialisation by holding down one of the buttons.

In my program, the processor is not reset, nor is there a button for deleting bonds.

After time the bond table fills up, until there is no memory to store new bonds: (BLE_GAP_EVT_DISCONNECTED => ble_bondmngr_bonded_masters_store => bond_info_store => NRF_ERROR_NO_MEM)

How do I delete old bonds (possibly all of them) when the bond table is full, to make room for new bonds.

I have tried the code below (both in the disconnected event and from main), but it crashes the softdevice:


    // check not connected
    // turn off advertising
    if (m_masters_in_db_count >= BLE_BONDMNGR_MAX_BONDED_MASTERS)
    {
        ble_bondmngr_bonded_masters_delete();
        load_all_from_flash();
        m_is_bondmngr_initialized = true;
    }

Parents
  • The code snippet you have there should work as far as I can see, but I'd strongly recommend you to check the error code you get from the function, to see if it succeded.

    Even when you do it from the disconnected event, you must make sure to do it before you start advertising again. Could this be the reason for your problem? (If you do this from the bond manager's event handler, the application's handler may have run before, and started advertising. I'd recommend you to have this kind of functionality in the application and not modify the bond manager anyway.)

    Also, if you give the bond manager an event handler when initializing it, you will get a BLE_BONDMNGR_EVT_BOND_FLASH_FULL event to it when the bond database is full. You can use this event to know when the flash is full, and then for example set a special value in GPREGRET, which is retained over resets, do a software reset and delete bond information on startup if this register is set to the special value.

    If you still have trouble, could you perhaps edit your question and elaborate a little on how exactly the softdevice crashes? Also, attaching your complete project would be helpful.

    Edit: Unfortunately, the above isn't quite correct with the current version of the bond manager. You will not get a FLASH_FULL event, instead you'll just get a call to the error handler with error code NRF_ERROR_NO_MEM (= 0x04). You will therefore have to use this to do a disconnect and delete for now. I've attached a modified version of the HTS application from the SDK that does this.

    ble_app_hts_bond_deletion.zip

Reply
  • The code snippet you have there should work as far as I can see, but I'd strongly recommend you to check the error code you get from the function, to see if it succeded.

    Even when you do it from the disconnected event, you must make sure to do it before you start advertising again. Could this be the reason for your problem? (If you do this from the bond manager's event handler, the application's handler may have run before, and started advertising. I'd recommend you to have this kind of functionality in the application and not modify the bond manager anyway.)

    Also, if you give the bond manager an event handler when initializing it, you will get a BLE_BONDMNGR_EVT_BOND_FLASH_FULL event to it when the bond database is full. You can use this event to know when the flash is full, and then for example set a special value in GPREGRET, which is retained over resets, do a software reset and delete bond information on startup if this register is set to the special value.

    If you still have trouble, could you perhaps edit your question and elaborate a little on how exactly the softdevice crashes? Also, attaching your complete project would be helpful.

    Edit: Unfortunately, the above isn't quite correct with the current version of the bond manager. You will not get a FLASH_FULL event, instead you'll just get a call to the error handler with error code NRF_ERROR_NO_MEM (= 0x04). You will therefore have to use this to do a disconnect and delete for now. I've attached a modified version of the HTS application from the SDK that does this.

    ble_app_hts_bond_deletion.zip

Children
No Data
Related