Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GATT caching and Peer manager issue

SDK: 15.3

Softdevice: 6.1.1

Board: Custom board

device: nrf52832

I have two boards, one central one peripheral role,and they has bonding togther. The central always power on, the peripheral keep sleep state most of time, and will connect to central when occurs interrupts. Inorder to save energy and time, it need to cache gatts services of peripheral. 

So first connection, central use ble_db_discovery.c to discover services of peripheral, and next time, it load services data from flash use pm_peer_data_remote_db_load. But when call this founction, the return code is NRF_ERROR_NOT_FOUND. I am sure it has bonding with perpheral.

this is the code

static void app_discovery_start(uint16_t conn_handle)
{
    ret_code_t err_code;
    pm_peer_id_t peer_id;
    ble_db_discovery_evt_t discv_evt;
    
    uint8_t gatt_db_buf[ALIGN_NUM(4, sizeof(ble_gatt_db_srv_t)*NUMBER_OF_SERVICE_CACHES)];
    ble_gatt_db_srv_t * xServiceCache = (ble_gatt_db_srv_t *) gatt_db_buf;
    uint16_t data_len = sizeof(gatt_db_buf);
    
    err_code = pm_peer_id_get(conn_handle, &peer_id);
    APP_ERROR_CHECK(err_code);
    if(peer_id != PM_PEER_ID_INVALID)            //Already bonding
    {
        err_code = pm_peer_data_remote_db_load(peer_id, xServiceCache, &data_len);
        APP_ERROR_CHECK(err_code);
        
        discv_evt.evt_type     = BLE_DB_DISCOVERY_COMPLETE;
        discv_evt.conn_handle  = conn_handle;
        for(uint8_t i = 0; i < NUMBER_OF_SERVICE_CACHES; i++)
        {
            memset(&discv_evt.params.discovered_db, 0, sizeof(discv_evt.params.discovered_db));
            memcpy(&discv_evt.params.discovered_db, &xServiceCache[i], sizeof(xServiceCache[i]));
            db_disc_handler(&discv_evt);
        }
    }
    else                                         //new device
    {
        err_code = ble_db_discovery_start(&m_db_disc, conn_handle);
        APP_ERROR_CHECK(err_code);
    }
}


static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    case BLE_GAP_EVT_CONNECTED:
    {
        app_discovery_start(p_gap_evt->conn_handle);

    } break;
    ....
}

So what can i do for gatt caching? and why wrong? Thanks for your comming answer.

Parents Reply Children
No Data
Related