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

How to discover custom service of peripheral

Hi, Nordic staff.

I'm working with Central device using S132.

There is a peripheral device using S112 in Nordic. I didn't make this peripheral.

My question is that is it possible to discover above service and some characteristics uuid from S132 central?

If possible, can tell me how should I do?

Best regards.

  • Do you know the service UUID & char. in peripheral side? If yes, you may define it in your code. If not, you may sniff the peripheral and try the service UUID and the characteristics data format. Sometimes the service UUID will be in advertisement data package.

  • Thank you for your prompt reply.

    I know the uuid value. Can you tell me how to define it?

  • For example discovery side:

    static ble_uuid_t const m_nus_uuid =
    {
    .uuid = BLE_UUID_NUS_SERVICE,
    .type = NUS_SERVICE_UUID_TYPE
    };

    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);

    if the notify char. enable notify in your code

    Then in your gatt discovery event add on char.

    void ble_gatt_on_db_disc_evt(ble_gatt_c_t * p_ble_gatt_c, const ble_db_discovery_evt_t * p_evt)
    {
    // Check if the GATT Service was discovered.
    if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
    p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE, &&
    p_evt->params.discovered_db.srv_uuid.type == NUS_SERVICE_UUID_TYPE) //p_ble_gatt_c->uuid_type)
    {
    ble_gatt_c_evt_t evt;

    evt.evt_type = BLE_GATT_C_EVT_DISCOVERY_COMPLETE;
    evt.conn_handle = p_evt->conn_handle;

    uint32_t i;
    for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
    {
    const ble_gatt_db_char_t * p_char = &(p_evt->params.discovered_db.charateristics[i]);
    switch (p_char->characteristic.uuid.uuid)
    {
    case UUID1_STATUS_CHAR:
    evt.params.peer_db.read2_handle = p_char->characteristic.handle_value;
    evt.params.peer_db.read2_cccd_handle = p_char->cccd_handle;
    ;
    break;
    case UUID2_STATUS_CHAR:
    evt.params.peer_db.read1_handle = p_char->characteristic.handle_value;
    evt.params.peer_db.read1_cccd_handle = p_char->cccd_handle;
    break;

    default:
    break;
    }
    }

    NRF_LOG_DEBUG("GATT Service discovered at peer.\r\n");
    //If the instance has been assigned prior to db_discovery, assign the db_handles
    if (p_ble_gatt_c->conn_handle != BLE_CONN_HANDLE_INVALID)
    {
    if ((p_ble_gatt_c->peer_gatt_db.write_handle == BLE_GATT_HANDLE_INVALID)&&
    (p_ble_gatt_c->peer_gatt_db.read1_handle == BLE_GATT_HANDLE_INVALID)&&
    (p_ble_gatt_c->peer_gatt_db.read1_cccd_handle == BLE_GATT_HANDLE_INVALID)&&
    (p_ble_gatt_c->peer_gatt_db.read2_handle == BLE_GATT_HANDLE_INVALID)&&
    (p_ble_gatt_c->peer_gatt_db.read2_cccd_handle == BLE_GATT_HANDLE_INVALID))
    {
    p_ble_gatt_c->peer_gatt_db = evt.params.peer_db;
    }
    }

    p_ble_gatt_c->evt_handler(p_ble_gatt_c, &evt);

    }
    }

    Get read or write char. in ble event  handler.

    static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)

    {

    }

  • Thank you for your answer.

    I'm using SDK17.

    Could you tell me the location of "ble_gatt_c_t" and "ble_gatt_c_evt_t"???

  • That's my project code. I think the example code should be ble_nus_c_t & ble_nus_c_evt_t

    The word meaning is the same.

    Because my application is the thermal meter with GATT client service. Make some miss-understand. Sorry for that.

Related