creating multiple services in a profile
Posted: Mon Mar 01, 2021 3:31 am
Hello.
In this tutorial: https://github.com/espressif/esp-idf/bl ... g-services
shows how to add services to a profile, characteristics to services, descriptors to characteristics.
First we define profile table:
And register that:
That call ESP_GATTS_REG_EVT event. In handler of that event we define service:
And create it:
That call ESP_GATTS_CREATE_EVT event. Using this event we define characteristic:
and create characteristic:
That call ESP_GATTS_ADD_CHAR_EVT event. We use it for adding descriptor:
And create descriptor:
What is the behavior of the program after calling the esp_ble_gatts_create_service () function? Will the execution be interrupted at this line of code and processing of the ESP_GATTS_CREATE_EVT event will start? Or does the ESP_GATTS_CREATE_EVT event start after the end of the ESP_GATTS_REG_EVT event?
So, in this code, we are creating one service, one characteristic and one descriptor. But if I need to add two services, how can I do it?
In this tutorial: https://github.com/espressif/esp-idf/bl ... g-services
shows how to add services to a profile, characteristics to services, descriptors to characteristics.
First we define profile table:
Code: Select all
static struct gatts_profile_inst gl_profile_tab[PROFILE_NUM] = {
[PROFILE_A_APP_ID] = {
.gatts_cb = gatts_profile_a_event_handler,
.gatts_if = ESP_GATT_IF_NONE,
[PROFILE_B_APP_ID] = {
.gatts_cb = gatts_profile_b_event_handler,
.gatts_if = ESP_GATT_IF_NONE,
},
};
Code: Select all
ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
Code: Select all
gl_profile_tab[PROFILE_A_APP_ID].service_id.is_primary = true;
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.inst_id = 0x00;
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
Code: Select all
esp_ble_gatts_create_service(gatts_if, &gl_profile_tab[PROFILE_A_APP_ID].service_id, GATTS_NUM_HANDLE_TEST_A);
Code: Select all
gl_profile_tab[PROFILE_A_APP_ID].service_handle = param->create.service_handle;
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.len = ESP_UUID_LEN_16;
gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A;
Code: Select all
esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].char_uuid,
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
a_property,
&gatts_demo_char1_val,
NULL);
Code: Select all
gl_profile_tab[PROFILE_A_APP_ID].char_handle = param->add_char.attr_handle;
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.len = ESP_UUID_LEN_16;
gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
Code: Select all
esp_err_t ret = esp_ble_gatts_add_char_descr(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].descr_uuid,
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, NULL, NULL);
So, in this code, we are creating one service, one characteristic and one descriptor. But if I need to add two services, how can I do it?