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

gatt service inquiry

Hi,

In addition to listening the advertiser's and beacon data we also need to offer the master application - which is connected to BLE-module via UART - the possibility to connect to peripheral and get information of available GATT-services. For this we need to be able to inquire service uuids from the connected peripheral.

I've been browsing through the examples but not been able to find out the solution for this. There are samples for listening the defined services, but not one for getting the information of all the available services.

Could anyone please guide me to the correct example, or give me some step-by-step information for building such an application.

Devkit used is nRF52840-DK, SDK revision is nRF5_SDK_16.0.0_98a08e2

Regards, Jukka

Parents
  • Hi Jukka

    If the UUIDs of the services are not known by the central, you'll have to register the UUIDs of the peripheral using ble_db_discovery_evt_register as described in the Database Discovery Module documentation before you can start discovery with ble_db_discovery_start.

    Best regards,

    Simon

  • Thank You Simon for your patience,

    No we are finally getting somewhere. Found exactly one example in SDK where the ble_db_discovery_evt_register()  function was used and based on that I made the following addition to initialization function:

    ble_uuid_t amt_uuid;

    amt_uuid.type = BLE_UUID_TYPE_BLE;
    amt_uuid.uuid = 0x180F;
    ble_db_discovery_evt_register(&amt_uuid);

    amt_uuid.uuid = 0x180A;
    ble_db_discovery_evt_register(&amt_uuid);

    amt_uuid.uuid = 0x1801;
    ble_db_discovery_evt_register(&amt_uuid);

    amt_uuid.uuid = 0x1800;
    ble_db_discovery_evt_register(&amt_uuid);

    And now getting the information quite as expected:

    scan_evt_handler: Connecting to target 7571823740d8
    ble_evt_handler: BLE_GAP_EVT_CONNECTED
    gatt_evt_handler: MTU exchange completed, Ble NUS max data length set to 20 bytes
    ble_evt_handler: BLE_GATTC_EVT_EXCHANGE_MTU_RSP: 23 bytes
    gatt_evt_handler: NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED
    ble_evt_handler: BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x101180F
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=1, charsx UUIDs: 0x1012A19
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=0
    ble_evt_handler: BLE_GATTC_EVT_DESC_DISC_RSP
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x2901180A
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=3, charsx UUIDs: 0x29012A23 0xFF012A26 0x12A27
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=1, charsx UUIDs: 0x29012A28
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x29011801
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=0
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x29011800
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x180F, count=1
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x180A, count=4
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x1801, count=0
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x1800, count=3
    BLE_DB_DISCOVERY_AVAILABLE
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=3, charsx UUIDs: 0x29012A00 0xFF012A01 0x12A04
    ble_evt_handler: BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST
    ble_evt_handler: BLE_GAP_EVT_CONN_PARAM_UPDATE
    ble_evt_handler: BLE_GAP_EVT_DISCONNECTED

    Summa summarum is that the answer to the original question is: no, there's no way to ask what services the peripheral has to offer, but one has to go through the services that we expect it to offer.

    I think that we can now continue with this. It was not quite what we expected and surely affects our plans in offering the command interface for our customers, but maybe they already know what to expect - better than we did.

    Once again, thanks for the great support.

    Regards, Jukka

Reply
  • Thank You Simon for your patience,

    No we are finally getting somewhere. Found exactly one example in SDK where the ble_db_discovery_evt_register()  function was used and based on that I made the following addition to initialization function:

    ble_uuid_t amt_uuid;

    amt_uuid.type = BLE_UUID_TYPE_BLE;
    amt_uuid.uuid = 0x180F;
    ble_db_discovery_evt_register(&amt_uuid);

    amt_uuid.uuid = 0x180A;
    ble_db_discovery_evt_register(&amt_uuid);

    amt_uuid.uuid = 0x1801;
    ble_db_discovery_evt_register(&amt_uuid);

    amt_uuid.uuid = 0x1800;
    ble_db_discovery_evt_register(&amt_uuid);

    And now getting the information quite as expected:

    scan_evt_handler: Connecting to target 7571823740d8
    ble_evt_handler: BLE_GAP_EVT_CONNECTED
    gatt_evt_handler: MTU exchange completed, Ble NUS max data length set to 20 bytes
    ble_evt_handler: BLE_GATTC_EVT_EXCHANGE_MTU_RSP: 23 bytes
    gatt_evt_handler: NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED
    ble_evt_handler: BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x101180F
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=1, charsx UUIDs: 0x1012A19
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=0
    ble_evt_handler: BLE_GATTC_EVT_DESC_DISC_RSP
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x2901180A
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=3, charsx UUIDs: 0x29012A23 0xFF012A26 0x12A27
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=1, charsx UUIDs: 0x29012A28
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x29011801
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=0
    ble_evt_handler: BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, count=1, UUIDs: 0x29011800
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x180F, count=1
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x180A, count=4
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x1801, count=0
    BLE_DB_DISCOVERY_COMPLETE: srv_uuid=0x1800, count=3
    BLE_DB_DISCOVERY_AVAILABLE
    ble_evt_handler: BLE_GATTC_EVT_CHAR_DISC_RSP: count=3, charsx UUIDs: 0x29012A00 0xFF012A01 0x12A04
    ble_evt_handler: BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST
    ble_evt_handler: BLE_GAP_EVT_CONN_PARAM_UPDATE
    ble_evt_handler: BLE_GAP_EVT_DISCONNECTED

    Summa summarum is that the answer to the original question is: no, there's no way to ask what services the peripheral has to offer, but one has to go through the services that we expect it to offer.

    I think that we can now continue with this. It was not quite what we expected and surely affects our plans in offering the command interface for our customers, but maybe they already know what to expect - better than we did.

    Once again, thanks for the great support.

    Regards, Jukka

Children
No Data
Related