Get device name of BLE client (smartphone) from BLE server (NRF52832) with only BLE peripheral mode

Hi Nordic team,

I'm using nRF52832, S132 with nRF5_SDK_17.1.0_ddde560 SDK. I currently implement BLE peripheral for the NRF52832 as it only healthcare sensor data to the smartphone. However, we want to keep track of which device has paired to the MCU and report the list of devices to connected smartphones to display on the mobile app. We want to store the BLE device name so it can be distinguished easily by the user. To achieve this, we want to read the BLE name of the connected device and store it in FDS. I have looked on the forum but it seems to me that the only way to read the device name of the smartphone is by using BLE central as well. Is it correct? I prefer to only use BLE peripheral mode to reduce power consumption and flash/ram usage as much as I can

If yes, I have followed a few examples but stuck at this point. I initialize the database discovery module below

NRF_BLE_GQ_DEF(m_ble_gatt_queue,                                                /**< BLE GATT Queue instance. */
               NRF_SDH_BLE_CENTRAL_LINK_COUNT,
               NRF_BLE_GQ_QUEUE_SIZE);
BLE_DB_DISCOVERY_DEF(m_db_disc);                            /**< Database discovery module instance. */


/**@brief Function for handling database discovery events.
 *
 * @details This function is a callback function to handle events from the database discovery module.
 *          Depending on the UUIDs that are discovered, this function forwards the events
 *          to their respective services.
 *
 * @param[in] p_event  Pointer to the database discovery event.
 */
static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
    
    uint32_t err_code; 
    uint16_t att_handle;

    ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;
    
    if (    (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
        &&  (p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_GAP)
        &&  (p_evt->params.discovered_db.srv_uuid.type == BLE_UUID_TYPE_BLE))
    {
        VMS_LOGLN("discovery complete");
        for (uint32_t i = 0; i < p_evt->params.discovered_db.char_count; i++)
        {
              if (p_chars[i].characteristic.uuid.uuid == BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME)
              {
                  att_handle = p_chars[i].characteristic.handle_value;
                  /*Found Device name characteristic - Start read procedure*/
                  err_code = sd_ble_gattc_read(p_evt->conn_handle, att_handle, 0);
                  APP_ERROR_CHECK(err_code);
              }
        }
    }
    
}


/** @brief Function for initializing the database discovery module. */
void db_discovery_init(void)
{
    static ble_uuid_t ble_uuid;
    ble_db_discovery_init_t db_init;

    ble_uuid.type = BLE_UUID_TYPE_BLE;
    ble_uuid.uuid = BLE_UUID_GAP;

    memset(&db_init, 0, sizeof(ble_db_discovery_init_t));

    db_init.evt_handler  = db_disc_handler;
    db_init.p_gatt_queue = &m_ble_gatt_queue;
    
    ret_code_t err_code = ble_db_discovery_init(&db_init);
    APP_ERROR_CHECK(err_code);

    err_code = ble_db_discovery_evt_register(&ble_uuid);
    APP_ERROR_CHECK(err_code);
}

In BLE_GAP_EVT_CONNECTED event, I call 

err_code = ble_db_discovery_start(&m_db_disc, p_ble_evt->evt.gap_evt.conn_handle);
            APP_ERROR_CHECK(err_code);
However, I wonder what event will sd_ble_gattc_read(p_evt->conn_handle, att_handle, 0); trigger? How can I read the string of the device name? I cannot find any example to follow up.
Best regards,
Xander
Related