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.

Parents Reply Children
  • 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.

  • Thank you. That's why I made it separately.
    Is this the right way to do it?
    But it hasn't been resolved...
    What should I do... ...TT.

    void MJR_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
    {
        ble_nus_c_evt_t nus_c_evt;
        memset(&nus_c_evt,0,sizeof(ble_nus_c_evt_t));
    
        ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;
    
        // Check if the NUS was discovered.
        if (    (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
            &&  (p_evt->params.discovered_db.srv_uuid.uuid == MJR_LE_SERVICE_UUID)
            &&  (p_evt->params.discovered_db.srv_uuid.type == NUS_SERVICE_UUID_TYPE))
        {
            uint32_t i;
            for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
            {
                switch (p_chars[i].characteristic.uuid.uuid)
                {
                    case MJR_LE_NOTIFYCATION_UUID:
    
                        nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                        break;
    
                    case MJR_LE_WRITE_NO_RESPONSE_UUID:
    
                        nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                        nus_c_evt.handles.nus_tx_cccd_handle = p_chars[i].cccd_handle;
                        break;
    
                    default:
                        break;
                }
            }
            if (p_ble_nus_c->evt_handler != NULL)
            {
                nus_c_evt.conn_handle = p_evt->conn_handle;
                nus_c_evt.evt_type    = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
                p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
            }
        }
    }

    static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
    {
        
        // ble_nus_c_on_db_disc_evt(&m_ble_nus_c, p_evt);
        MJR_c_on_db_disc_evt(&m_ble_nus_c, p_evt);
    
    }

Related