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

  • The device connected is a sealed box, only access to it's secrets is the Nordic Android tool. I have the following log file and partial snapshot to offer:

    nRF Connect, 2020-02-19
    WGX_iBeacon (D8:40:37:82:71:75)
    I	08:11:46.114	[Server] Server started
    V	08:11:46.139	Heart Rate (0x180D)
    - Heart Rate Measurement [N] (0x2A37)
       Client Characteristic Configuration (0x2902)
    - Body Sensor Location [R] (0x2A38)
    - Heart Rate Control Point [W] (0x2A39)
    Unknown Service (0000aaa0-0000-1000-8000-aabbccddeeff)
    - Unknown Characteristic [N R] (0000aaa1-0000-1000-8000-aabbccddeeff)
       Client Characteristic Configuration (0x2902)
       Unknown Descriptor (0000aab0-0000-1000-8000-aabbccddeeff)
       Characteristic User Description (0x2901)
       Characteristic Presentation Format (0x2904)
    - Unknown Characteristic [I W WNR] (0000aaa2-0000-1000-8000-aabbccddeeff)
       Client Characteristic Configuration (0x2902)
    User Data (0x181C)
    - First Name [R W] (0x2A8A)
    - Last Name [R W] (0x2A90)
    - Gender [R W] (0x2A8C)
    V	08:11:46.460	Connecting to D8:40:37:82:71:75...
    D	08:11:46.460	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
    D	08:11:46.767	[Server callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	08:11:46.767	[Server] Device with address D8:40:37:82:71:75 connected
    D	08:11:46.781	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	08:11:46.781	Connected to D8:40:37:82:71:75
    D	08:11:46.789	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    V	08:11:46.805	Discovering services...
    D	08:11:46.805	gatt.discoverServices()
    D	08:11:46.812	[Callback] Services discovered with status: 0
    I	08:11:46.813	Services discovered
    V	08:11:46.827	Generic Access (0x1800)
    - Device Name [R W] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    Generic Attribute (0x1801)
    Device Information (0x180A)
    - System ID [R] (0x2A23)
    - Firmware Revision String [R] (0x2A26)
    - Hardware Revision String [R] (0x2A27)
    - Software Revision String [R] (0x2A28)
    Unknown Service (0000ffa0-0000-1000-8000-00805f9b34fb)
    - Unknown Characteristic [R W] (0000ffa1-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000ffa2-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [N R] (0000ffa3-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
       Client Characteristic Configuration (0x2902)
    - Unknown Characteristic [N R] (0000ffa4-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
       Client Characteristic Configuration (0x2902)
    - Unknown Characteristic [N R] (0000ffa5-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
       Client Characteristic Configuration (0x2902)
    Unknown Service (0000ffb0-0000-1000-8000-00805f9b34fb)
    - Unknown Characteristic [R W] (0000ffb1-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000ffb2-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [N R] (0000ffb3-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
       Client Characteristic Configuration (0x2902)
    Unknown Service (0000fff0-0000-1000-8000-00805f9b34fb)
    - Unknown Characteristic [R W] (0000fff1-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff2-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff3-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff4-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff5-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff6-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff7-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fff8-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [W] (0000fff9-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [R W] (0000fffe-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    - Unknown Characteristic [W] (0000ffff-0000-1000-8000-00805f9b34fb)
       Characteristic User Description (0x2901)
    Battery Service (0x180F)
    - Battery Level [N R] (0x2A19)
       Client Characteristic Configuration (0x2902)
    D	08:11:46.828	gatt.setCharacteristicNotification(0000ffa3-0000-1000-8000-00805f9b34fb, true)
    D	08:11:46.829	gatt.setCharacteristicNotification(0000ffa4-0000-1000-8000-00805f9b34fb, true)
    D	08:11:46.830	gatt.setCharacteristicNotification(0000ffa5-0000-1000-8000-00805f9b34fb, true)
    D	08:11:46.831	gatt.setCharacteristicNotification(0000ffb3-0000-1000-8000-00805f9b34fb, true)
    D	08:11:46.832	gatt.setCharacteristicNotification(00002a19-0000-1000-8000-00805f9b34fb, true)
    I	08:11:52.141	Connection parameters updated (interval: 997.5ms, latency: 0, timeout: 4000ms)
    V	08:12:58.877	Reading all characteristics...
    V	08:12:58.877	Reading characteristic 00002a00-0000-1000-8000-00805f9b34fb
    D	08:12:58.877	gatt.readCharacteristic(00002a00-0000-1000-8000-00805f9b34fb)
    I	08:12:59.966	Read Response received from 00002a00-0000-1000-8000-00805f9b34fb, value: (0x) 57-47-58-5F-69-42-65-61-63-6F-6E, "WGX_iBeacon"
    A	08:12:59.966	"WGX_iBeacon" received
    V	08:12:59.971	Reading characteristic 00002a01-0000-1000-8000-00805f9b34fb
    D	08:12:59.971	gatt.readCharacteristic(00002a01-0000-1000-8000-00805f9b34fb)
    I	08:13:02.960	Read Response received from 00002a01-0000-1000-8000-00805f9b34fb, value: (0x) 40-02
    A	08:13:02.960	"[576] Generic Keyring (Generic category)" received
    V	08:13:02.963	Reading characteristic 00002a04-0000-1000-8000-00805f9b34fb
    D	08:13:02.963	gatt.readCharacteristic(00002a04-0000-1000-8000-00805f9b34fb)
    I	08:13:04.958	Read Response received from 00002a04-0000-1000-8000-00805f9b34fb, value: (0x) 90-01-20-03-00-00-90-01
    A	08:13:04.958	"Connection Interval: 500.00ms - 1000.00ms,
    Slave Latency: 0,
    Supervision Timeout Multiplier: 400" received
    V	08:13:04.963	Reading characteristic 00002a23-0000-1000-8000-00805f9b34fb
    D	08:13:04.963	gatt.readCharacteristic(00002a23-0000-1000-8000-00805f9b34fb)
    I	08:13:06.952	Read Response received from 00002a23-0000-1000-8000-00805f9b34fb, value: (0x) 75-71-82-37-40-D8-00-00
    A	08:13:06.952	"(0x) 75-71-82-37-40-D8-00-00" received
    V	08:13:06.957	Reading characteristic 00002a26-0000-1000-8000-00805f9b34fb
    D	08:13:06.957	gatt.readCharacteristic(00002a26-0000-1000-8000-00805f9b34fb)
    I	08:13:08.947	Read Response received from 00002a26-0000-1000-8000-00805f9b34fb, value: (0x) 57-47-58-32-30-31-36-31-31-30-38-32-33-32-38-33-35-4E-00-00
    A	08:13:08.947	"WGX20161108232835N" received
    V	08:13:08.959	Reading characteristic 00002a27-0000-1000-8000-00805f9b34fb
    D	08:13:08.959	gatt.readCharacteristic(00002a27-0000-1000-8000-00805f9b34fb)
    I	08:13:10.941	Read Response received from 00002a27-0000-1000-8000-00805f9b34fb, value: (0x) 4E-52-46-35-31-38-32-32-51-46-41-41-48-30-00-00-00-00-00-00
    A	08:13:10.941	"NRF51822QFAAH0" received
    V	08:13:10.952	Reading characteristic 00002a28-0000-1000-8000-00805f9b34fb
    D	08:13:10.952	gatt.readCharacteristic(00002a28-0000-1000-8000-00805f9b34fb)
    I	08:13:14.930	Read Response received from 00002a28-0000-1000-8000-00805f9b34fb, value: (0x) 6E-52-46-35-5F-53-44-4B-5F-31-31-2E-30-2E-30-5F-38-39-61-38-31-39-37-00-00
    A	08:13:14.930	"nRF5_SDK_11.0.0_89a8197" received
    V	08:13:14.939	Reading characteristic 0000ffa1-0000-1000-8000-00805f9b34fb
    D	08:13:14.939	gatt.readCharacteristic(0000ffa1-0000-1000-8000-00805f9b34fb)
    I	08:13:16.927	Read Response received from 0000ffa1-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:16.927	"(0x) 00" received
    V	08:13:16.936	Reading characteristic 0000ffa2-0000-1000-8000-00805f9b34fb
    D	08:13:16.936	gatt.readCharacteristic(0000ffa2-0000-1000-8000-00805f9b34fb)
    I	08:13:18.921	Read Response received from 0000ffa2-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:18.921	"(0x) 00" received
    V	08:13:18.934	Reading characteristic 0000ffa3-0000-1000-8000-00805f9b34fb
    D	08:13:18.934	gatt.readCharacteristic(0000ffa3-0000-1000-8000-00805f9b34fb)
    I	08:13:20.915	Read Response received from 0000ffa3-0000-1000-8000-00805f9b34fb, value: (0x) 01-01
    A	08:13:20.915	"(0x) 01-01" received
    V	08:13:20.926	Reading characteristic 0000ffa4-0000-1000-8000-00805f9b34fb
    D	08:13:20.927	gatt.readCharacteristic(0000ffa4-0000-1000-8000-00805f9b34fb)
    I	08:13:22.910	Read Response received from 0000ffa4-0000-1000-8000-00805f9b34fb, value: (0x) C1-FF
    A	08:13:22.910	"(0x) C1-FF" received
    V	08:13:22.918	Reading characteristic 0000ffa5-0000-1000-8000-00805f9b34fb
    D	08:13:22.918	gatt.readCharacteristic(0000ffa5-0000-1000-8000-00805f9b34fb)
    I	08:13:24.905	Read Response received from 0000ffa5-0000-1000-8000-00805f9b34fb, value: (0x) 00-00
    A	08:13:24.905	"(0x) 00-00" received
    V	08:13:24.915	Reading characteristic 0000ffb1-0000-1000-8000-00805f9b34fb
    D	08:13:24.915	gatt.readCharacteristic(0000ffb1-0000-1000-8000-00805f9b34fb)
    I	08:13:26.896	Read Response received from 0000ffb1-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:26.896	"(0x) 00" received
    V	08:13:26.905	Reading characteristic 0000ffb2-0000-1000-8000-00805f9b34fb
    D	08:13:26.905	gatt.readCharacteristic(0000ffb2-0000-1000-8000-00805f9b34fb)
    I	08:13:28.896	Read Response received from 0000ffb2-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:28.896	"(0x) 00" received
    V	08:13:28.897	Reading characteristic 0000ffb3-0000-1000-8000-00805f9b34fb
    D	08:13:28.897	gatt.readCharacteristic(0000ffb3-0000-1000-8000-00805f9b34fb)
    I	08:13:30.891	Read Response received from 0000ffb3-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:30.891	"(0x) 00" received
    V	08:13:30.905	Reading characteristic 0000fff1-0000-1000-8000-00805f9b34fb
    D	08:13:30.905	gatt.readCharacteristic(0000fff1-0000-1000-8000-00805f9b34fb)
    I	08:13:32.883	Read Response received from 0000fff1-0000-1000-8000-00805f9b34fb, value: (0x) 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    A	08:13:32.883	"(0x) 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00" received
    V	08:13:32.894	Reading characteristic 0000fff2-0000-1000-8000-00805f9b34fb
    D	08:13:32.895	gatt.readCharacteristic(0000fff2-0000-1000-8000-00805f9b34fb)
    I	08:13:34.881	Read Response received from 0000fff2-0000-1000-8000-00805f9b34fb, value: (0x) 00-00
    A	08:13:34.881	"(0x) 00-00" received
    V	08:13:34.892	Reading characteristic 0000fff3-0000-1000-8000-00805f9b34fb
    D	08:13:34.892	gatt.readCharacteristic(0000fff3-0000-1000-8000-00805f9b34fb)
    I	08:13:36.871	Read Response received from 0000fff3-0000-1000-8000-00805f9b34fb, value: (0x) 00-00
    A	08:13:36.871	"(0x) 00-00" received
    V	08:13:36.876	Reading characteristic 0000fff4-0000-1000-8000-00805f9b34fb
    D	08:13:36.876	gatt.readCharacteristic(0000fff4-0000-1000-8000-00805f9b34fb)
    I	08:13:38.868	Read Response received from 0000fff4-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:38.868	"(0x) 00" received
    V	08:13:38.868	Reading characteristic 0000fff5-0000-1000-8000-00805f9b34fb
    D	08:13:38.869	gatt.readCharacteristic(0000fff5-0000-1000-8000-00805f9b34fb)
    I	08:13:40.863	Read Response received from 0000fff5-0000-1000-8000-00805f9b34fb, value: (0x) 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    A	08:13:40.863	"(0x) 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00" received
    V	08:13:40.866	Reading characteristic 0000fff6-0000-1000-8000-00805f9b34fb
    D	08:13:40.866	gatt.readCharacteristic(0000fff6-0000-1000-8000-00805f9b34fb)
    I	08:13:42.860	Read Response received from 0000fff6-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:42.860	"(0x) 00" received
    V	08:13:42.866	Reading characteristic 0000fff7-0000-1000-8000-00805f9b34fb
    D	08:13:42.866	gatt.readCharacteristic(0000fff7-0000-1000-8000-00805f9b34fb)
    I	08:13:44.851	Read Response received from 0000fff7-0000-1000-8000-00805f9b34fb, value: (0x) 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    A	08:13:44.851	"(0x) 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00" received
    V	08:13:44.854	Reading characteristic 0000fff8-0000-1000-8000-00805f9b34fb
    D	08:13:44.854	gatt.readCharacteristic(0000fff8-0000-1000-8000-00805f9b34fb)
    I	08:13:46.847	Read Response received from 0000fff8-0000-1000-8000-00805f9b34fb, value: (0x) 00
    A	08:13:46.847	"(0x) 00" received
    V	08:13:46.850	Reading characteristic 0000fffe-0000-1000-8000-00805f9b34fb
    D	08:13:46.850	gatt.readCharacteristic(0000fffe-0000-1000-8000-00805f9b34fb)
    I	08:13:48.845	Read Response received from 0000fffe-0000-1000-8000-00805f9b34fb, value: (0x) 00-00
    A	08:13:48.845	"(0x) 00-00" received
    V	08:13:48.850	Reading characteristic 00002a19-0000-1000-8000-00805f9b34fb
    D	08:13:48.850	gatt.readCharacteristic(00002a19-0000-1000-8000-00805f9b34fb)
    I	08:13:50.839	Read Response received from 00002a19-0000-1000-8000-00805f9b34fb, value: (0x) 64, "d"
    A	08:13:50.839	"100%" received
    V	08:13:50.843	25 characteristics read

  • Hi Jukka

    In your db_disc_handler function, what events are you calling? If you see the db_disc_handler in I.E. the original ble_app_uart_c example you can see the ble_nus_c_on_db_disc_evt() which handles the discovery correctly. You can see that you have to know the UUIDs and UUID types of services you want to discover. Have you done so in your application?

    Best regards,

    Simon

  • Hello Simon,

    The db_disc_handler() is quite original, only addition is to have debug prints there:

    static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
    {
        if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE)
        {
            printf("BLE_DB_DISCOVERY_COMPLETE: srv_uuid=%u, count=%u\r\n", p_evt->params.discovered_db.srv_uuid.uuid, p_evt->params.discovered_db.char_count);
        }
        else if (p_evt->evt_type == BLE_DB_DISCOVERY_ERROR)
        {
            printf("BLE_DB_DISCOVERY_ERROR: error=%u\r\n", p_evt->params.err_code);
        }
        else if (p_evt->evt_type == BLE_DB_DISCOVERY_AVAILABLE)
        {
            printf("BLE_DB_DISCOVERY_AVAILABLE\r\n");
        }
        else if (p_evt->evt_type == BLE_DB_DISCOVERY_SRV_NOT_FOUND)
        {
            printf("BLE_DB_DISCOVERY_SRV_NOT_FOUND\r\n");
        }
    
        ble_nus_c_on_db_disc_evt(&m_ble_nus_c, p_evt);
    }

    However, does your comment "you have to know the UUIDs and UUID types of services you want to discover" mean that actually one can't discover what services the peripheral has got to offer, but it must asked if the peripheral offers the services that we are expecting?

    BR, Jukka

  • 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

Related