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

Central reading characteristic value

I have NRF5252840-DK (evaluation board, SDK 15.3.0, S140) acting as central. It correctly scans advertising data from my peripheral - custom board with NRF52811 (same SDK, based on Beacon project, but with added capability to connect and with added custom service and characteristics with 128b UUID).

My central (NRF5252840-DK ) can correctly connect to peripheral, and with

err_code=ble_db_discovery_start(&m_db_disc, p_gap_evt->conn_handle);

I can discover my service, and my two custom characteristics although it takes a while (about 50 seconds). Then I find myself in db_disc_handler, with event type BLE_DB_DISCOVERY_COMPLETE.

 * @param[in] p_event  Pointer to the database discovery event.
 */
static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
        ret_code_t       err_code;
    NRF_LOG_INFO("db_disc_handler");
    if(p_evt->evt_type==BLE_DB_DISCOVERY_COMPLETE)
    {
        NRF_LOG_INFO("Discovered");

        ble_gatts_value_t  	temp;
        memset(&temp, 0, sizeof(ble_gatts_value_t));
        memset(&temp, 0, sizeof(my_value_arr));
        temp.p_value   = &my_value_arr[0];
        temp.len      = 3;
        temp.offset   = 0;
        err_code = sd_ble_gatts_value_get(p_evt->conn_handle, p_evt->params.discovered_db.charateristics[0].characteristic.handle_value, &temp); // 0x00D
        APP_ERROR_CHECK(err_code);

    }

Characteristics can be read (0x01 in p_evt->params.discovered_db.characteristics[0].characteristic.char_props.read), and I can read their values by my phone app. UUID for characteristic is correct. I did not get any disconnect event, but sd_ble_gatts_value_get returns error 5 (NRF_ERROR_NOT_FOUND?). What might be interesting is that p_evt->params.err_code is equal to 0x00021400. Does that have anything to do with RAM? I already modified my linker in SES v4.20a to:

RAM_START=0x20001f10
RAM_SIZE=0x3e330

I should also mention, that I tried to read characteristic with sd_ble_gattc_read();, and it did not trow any errors, but p_evt->evt_id == BLE_GATTC_EVT_READ_RSP in gatt_evt_handler was never true. I'm new to NRF52, so I might have missed something obvious, but I spent hours reading forums, and examples so I would be very grateful for help.

  • I don't think you can call sd_ble_gatts_value_get() from a client. The function belongs to the header file ble_gatts.h (Generic Attribute Profile (GATT) Server) and has to be called from your peripheral (which is the server and contains the attribute table). For the client (in your case the central) you have to use the functions in the header file ble_gattc.h.

    See this case, which is related to yours.

    Best regards,

    Simon

Related