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
  • Hi Ole,

    To fulfil your suggestions, I started with the blank ble_app_hts example provided by Nordic.

    I pasted the following function at the bottom of ble_bondmngr.c (and stuck a prototype at the top of the main.c file).

    void delete_the_bond_table(void)
    {
    	uint32_t err_code;
    	
    	err_code = ble_bondmngr_bonded_masters_delete();
    	APP_ERROR_CHECK(err_code);
    	
    	err_code = load_all_from_flash();
    	APP_ERROR_CHECK(err_code);
    	
    	m_is_bondmngr_initialized = true;
    }
    

    I then changed [main.c => on_ble_evt() => BLE_GAP_EVT_DISCONNECTED] to include a call to this function before storing bonded masters (and before re-starting advertising):

    	// Since we are not in a connection and have not started advertising, store bonds
    	delete_the_bond_table();
    	err_code = ble_bondmngr_bonded_masters_store();
    	APP_ERROR_CHECK(err_code);
    

    I compiled, set breakpoints in app_error_handler and assert_nrf_callback, then launched the debugger.

    I then used the dongle and Nordic Master Control Panel to open and close a connection.

    Result: ble_bondmngr_bonded_masters_store now returns NRF_ERROR_INTERNAL.

    Investigation shows that this is returned by a sub-call to master_update() which fails because m_master.bond.master_handle is now no longer set.

    I then deleted this above call, and entered the following in place of the main() function's eternal loop:

    	uint32_t delete_bonds_flag = false;
    	uint32_t err_code;
    
    	...
    
    	// Enter main loop
    	for(;;)
    	{
    		//power_manage();
    		
    		if (m_conn_handle != BLE_CONN_HANDLE_INVALID) // connected
    		{
    			delete_bonds_flag = true;
    		}
    		else if (delete_bonds_flag) // NOT connected
    		{
    			err_code = sd_ble_gap_adv_stop();
    			APP_ERROR_CHECK(err_code);
    			advertising_start();
    				
    			delete_the_bond_table();
    
    			delete_bonds_flag = false;
    		}
    	}
    

    I compiled, set breakpoints in app_error_handler and assert_nrf_callback, then launched the debugger.

    I then used the dongle and Nordic Master Control Panel to open and close a connection.

    Result: No errors caught using breakpoints, but there is no advertising (checked with Master Control Panel and iPhone BLE app) and no further connection possible. The debugger stops at an unknown location.

    Please advise me what code should be used to clear the bonding table, and where it should be called from in the ble_app_hts example code (without resetting the processor).

  • I meant the edit to my previous answer, not the comment. Sorry.

Reply Children
No Data
Related