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

how to get the number of bonding informations stored.......?

Hai

i am using mbed to program my nrf51822. i need to implement bonding in my application. for that i am using securitymanager. and i have changed DEVICE_MANAGER_MAX_BONDS to 24 in device_manager_config.h. now i am able to store 24 bonding information. but when i bond a 25th device nrf51822 gets hang. so i need to get the number of bonds at any time and i need to clear that info when it is equal to DEVICE_MANAGER_MAX_BONDS. so is there any way to get the number of bonds............?

Parents
  • Hi,

    The device manager does not expose an API for retrieving number of stored bonds in flash directly, but you can use the dm_service_context_get() function which will return NRF_SUCCESS for stored entries.

    uint8_t bonds_count_get(void)
    
    {
    
       uint32_t                       err_code;
    
       uint8_t                        cnt = 0;
    
       dm_handle_t                    p_handle;
    
       static dm_service_context_t    service_context;
    
       memset(&p_handle, 0, sizeof(dm_handle_t));
    
       for (uint8_t i=0; i < DEVICE_MANAGER_MAX_BONDS; i++)
    
       {
    
            err_code = dm_service_context_get(&p_handle, &service_context);
    
            if(err_code == NRF_SUCCESS)
    
            {
    
                 cnt++;
    
            }
    
            else if(err_code == NRF_ERROR_INVALID_STATE)
    
           {
    
                  APP_ERROR_CHECK(err_code);
    
            }
    
           
    
            p_handle.device_id++;
    
        }
    
    return cnt;
    
    }
    
Reply
  • Hi,

    The device manager does not expose an API for retrieving number of stored bonds in flash directly, but you can use the dm_service_context_get() function which will return NRF_SUCCESS for stored entries.

    uint8_t bonds_count_get(void)
    
    {
    
       uint32_t                       err_code;
    
       uint8_t                        cnt = 0;
    
       dm_handle_t                    p_handle;
    
       static dm_service_context_t    service_context;
    
       memset(&p_handle, 0, sizeof(dm_handle_t));
    
       for (uint8_t i=0; i < DEVICE_MANAGER_MAX_BONDS; i++)
    
       {
    
            err_code = dm_service_context_get(&p_handle, &service_context);
    
            if(err_code == NRF_SUCCESS)
    
            {
    
                 cnt++;
    
            }
    
            else if(err_code == NRF_ERROR_INVALID_STATE)
    
           {
    
                  APP_ERROR_CHECK(err_code);
    
            }
    
           
    
            p_handle.device_id++;
    
        }
    
    return cnt;
    
    }
    
Children
Related