BLE: How change UUID16 by UUID128

GustavoGB
Posts: 18
Joined: Fri Jan 15, 2021 1:46 am

BLE: How change UUID16 by UUID128

Postby GustavoGB » Fri Jan 15, 2021 1:58 am

Hello, I am using the example https://github.com/espressif/esp-idf/bl ... eat_demo.c that sets all UUIDs (Service and Characteristics) to 16 bits by default, however I am interested in setting them to 128 bits.
But I'm having a lot of problems since I don't know what to modify.
I'm pretty sure all I have to do is within the following code excerpt:

Code: Select all

static const uint16_t GATTS_SERVICE_UUID_TEST      = 0x00FF;
static const uint16_t GATTS_CHAR_UUID_TEST_A       = 0xFF01;

Code: Select all

static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
{
    // Service Declaration
    [IDX_SVC]        =
    {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
      sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_TEST), (uint8_t *)&GATTS_SERVICE_UUID_TEST}},

    /* Characteristic Declaration */
    [IDX_CHAR_A]     =
    {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
      CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}},

    /* Characteristic Value */
    [IDX_CHAR_VAL_A] =
    {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&GATTS_CHAR_UUID_TEST_A, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
      GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},

.
.
.
If anyone has any advice to modify the code to get UUID128, I will be very grateful.
Thanks a lot :D :D

Gustavo

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: BLE: How change UUID16 by UUID128

Postby ESP_Minatel » Fri Jan 15, 2021 1:15 pm

Hi,


You can take a look at the ANCS example to see how to deal with UUID128. I'm supposing that you are using bluedroid, not NimBLE, right?

https://github.com/espressif/esp-idf/tr ... e/ble_ancs

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: BLE: How change UUID16 by UUID128

Postby ESP_Minatel » Fri Jan 15, 2021 3:45 pm

Hi,

You can also try to change the gatt_server example ESP-IDF Gatt Server Demo (for ESP-IDF version 4.2).

Change from:

Code: Select all

#define GATTS_SERVICE_UUID_TEST_A   0x00FF
To:

Code: Select all

uint8_t gatts_service_uuid128_test_a[ESP_UUID_LEN_16] = {0x06, 0x18, 0x7a, 0xec, 0xbe, 0x11, 0x11, 0xea, 0x00, 0x16, 0x02, 0x42, 0x01, 0x13, 0x00, 0x04};
And:

Code: Select all

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;
To:

Code: Select all

gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_128;
memcpy(gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid128, gatts_service_uuid128_test_a,ESP_UUID_LEN_128);

Hope this could help you!

GustavoGB
Posts: 18
Joined: Fri Jan 15, 2021 1:46 am

Re: BLE: How change UUID16 by UUID128

Postby GustavoGB » Tue Jan 19, 2021 2:13 pm

ESP_Minatel wrote:
Fri Jan 15, 2021 3:45 pm
Hi,

You can also try to change the gatt_server example ESP-IDF Gatt Server Demo (for ESP-IDF version 4.2).

Change from:

Code: Select all

#define GATTS_SERVICE_UUID_TEST_A   0x00FF
To:

Code: Select all

uint8_t gatts_service_uuid128_test_a[ESP_UUID_LEN_16] = {0x06, 0x18, 0x7a, 0xec, 0xbe, 0x11, 0x11, 0xea, 0x00, 0x16, 0x02, 0x42, 0x01, 0x13, 0x00, 0x04};
And:

Code: Select all

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;
To:

Code: Select all

gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_128;
memcpy(gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid128, gatts_service_uuid128_test_a,ESP_UUID_LEN_128);

Hope this could help you!

Excellent ESP_Minatel!, works in this way. Only I had to do a little modification to your code.
In several places you put ESP_UUID_LEN_16, when it should be ESP_UUID_LEN_128 in all cases.
Thanks for your help, I couldn't have done it without you telling me.

I have another question to ask you, I don't know if we can follow this post or should I make a new one.
It is about modifying Characteristics Values from the same code during the execution of the program. I'm having trouble doing it as

Code: Select all

esp_ble_gatts_set_attr_value(42, sizeof(char_value), (uint8_t *)char_value))
because doesn't seem to work.
If you want we do another post.

Again, thank you very much ESP_Minatel.

Gustavo

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: BLE: How change UUID16 by UUID128

Postby ESP_Minatel » Tue Jan 19, 2021 2:46 pm

Hi Gustavo,


You're welcome! :D

It's better to create a new topic and then we could help others on the same issue.

Tanuja Gudaje
Posts: 3
Joined: Thu May 25, 2023 7:29 am

Re: BLE: How change UUID16 by UUID128

Postby Tanuja Gudaje » Tue Jun 13, 2023 11:49 am

Hi ,

I am working on EP32 module as peripheral. and I am trying to add one more service in the gatts_gattc_coex .
I am not able to get the customized UUID in the android app.

#define GATTS_SERVICE_UUID_LOC_NAV 0x00DD
#define GATTS_CHAR_UUID_LOC_NAV 0xDD01
#define GATTS_NUM_HANDLE_LOC_NAV 3

Can you please help me get it work?

Kind Regards,
tanuja

Who is online

Users browsing this forum: atique, Baidu [Spider] and 202 guests