How to handle custom BLE services when ESP32 is gatt client?

Posts: 94
Joined: Wed Apr 05, 2017 12:49 pm

How to handle custom BLE services when ESP32 is gatt client?

Postby newsettler_AI » Mon May 21, 2018 10:11 am


I'm have ESP32 as gatt client and other ble module (nrf52) which runing as gatt server.
There 4 services on nrf52 side: Battery service (0x180F) , Device information (0x180A), Heart rate service (0x180D) and one custom 128 bit service (

I'm stuck with profile handler on ESP32 side.

Let see on Battery service (0x180F).
There are next fields that I see via nRFConnect application:

Battery level UUID: 0x2A19
Property: NOTIFY, READ
Value: 99 (%)

Client Characteristic cpnfiguration
Value: Notifications enabled

I have discovered service in gatt_event_handler:

Code: Select all

        esp_err_t ret_search_gatt;
        ret_search_gatt = esp_ble_gattc_search_service(gattc_if, param->cfg_mtu.conn_id, NULL);
        if(ret_search_gatt != ESP_OK)
            ESP_LOGI(BLE_TAG, "ERR: esp_ble_gattc_search_service, error code = %x", ret_search_gatt);
ok, how I see all 4 profiles there. But how can find values? Should I do something like this:

Code: Select all

        esp_gatt_srvc_id_t *srvc_id =(esp_gatt_srvc_id_t *)&p_data->search_res.srvc_id;

        ESP_LOGI(BLE_TAG, "srvc_id_len:%d [%x]", srvc_id->id.uuid.len, srvc_id->id.uuid.len);
        for (uint8_t i = 0; i < 15; i++)
            ESP_LOGI(BLE_TAG, "srvc_id:%d [%x]", i, srvc_id->id.uuid.uuid.uuid128[i]);

        if (srvc_id->id.uuid.len == ESP_UUID_LEN_16 && srvc_id->id.uuid.uuid.uuid16 == BATTERY_SERVICE) {
            ESP_LOGI(BLE_TAG, "battery service found");
            get_server = true;
            gl_profile_tab[PROFILE_BATTERY_SERVICE].service_start_handle = p_data->search_res.start_handle;
            gl_profile_tab[PROFILE_BATTERY_SERVICE].service_end_handle = p_data->search_res.end_handle;
            ESP_LOGI(BLE_TAG, "UUID16: %x", srvc_id->id.uuid.uuid.uuid16);

And one more thing. As I see in ESP32 example, only one profile is predefined on client's side so one connection is opened: ... emo.c#L341

So, in my case (4 services) I need to open 4 connections?

Code: Select all

esp_ble_gattc_open(gl_profile_tab[PROFILE_BATTERY_SERVICE].gattc_if, scan_result->scan_rst.bda, true);
esp_ble_gattc_open(gl_profile_tab[PROFILE_DEVICE_INFO].gattc_if, scan_result->scan_rst.bda, true);
esp_ble_gattc_open(gl_profile_tab[PROFILE_HRM].gattc_if, scan_result->scan_rst.bda, true);
esp_ble_gattc_open(gl_profile_tab[PROFILE_CUSTOM].gattc_if, scan_result->scan_rst.bda, true);

Who is online

Users browsing this forum: No registered users and 18 guests