esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

Adding new services to GATTS is invalid (IDFGH-12744)

Open Dylanliacc opened this issue 1 year ago • 2 comments

Answers checklist.

  • [X] I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • [X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • [X] I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

V5.2.1

Espressif SoC revision.

ESP32S3

Operating System used.

Linux

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

Custom board

Power Supply used.

USB

What is the expected behavior?

Use The example esp\v5.2.1\esp-idf\examples\bluetooth\bluedroid\ble\gatt_server use function esp_ble_gatts_add_char() to add a new cha

Works correctly when using routine to add two characteristics

What is the actual behavior?

When I try to use the function esp_ble_gatts_add_char()to add one more characteristic value to the service Only one can be added

case ESP_GATTS_CREATE_EVT: ESP_LOGI(GATTS_TAG, "CREATE_SERVICE_EVT, status %d, service_handle %d", param->create.status, param->create.service_handle);

    gl_profile_tab[PROFILE_A_APP_ID].service_handle = param->create.service_handle;
  
    gl_profile_tab[PROFILE_A_APP_ID].char_uuid_read.len = ESP_UUID_LEN_128;
   
    gl_profile_tab[PROFILE_A_APP_ID].char_uuid_write.len = ESP_UUID_LEN_128;
    uint8_t char_uuid_write[ESP_UUID_LEN_128] = {};


    uint8_t char_uuid_read[ESP_UUID_LEN_128] = {};
    for (int i = 0; i < ESP_UUID_LEN_128; i++)
    {
        gl_profile_tab[PROFILE_A_APP_ID].char_uuid_write.uuid.uuid128[i] = char_uuid_write[i];
    }
    for (int i = 0; i < ESP_UUID_LEN_128; i++)
    {
        gl_profile_tab[PROFILE_A_APP_ID].char_uuid_read.uuid.uuid128[i] = char_uuid_read[i];
    }

    esp_ble_gatts_start_service(gl_profile_tab[PROFILE_A_APP_ID].service_handle);

    a_property = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_NOTIFY;



    esp_err_t add_char_ret = esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].char_uuid_write,
                                                    ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
                                                    a_property,
                                                    &gatts_demo_char1_val, NULL);
    if (add_char_ret)
    {
        ESP_LOGE(GATTS_TAG, "add char1 failed, error code =%x", add_char_ret);
    }


    add_char_ret = esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, &gl_profile_tab[PROFILE_A_APP_ID].char_uuid_read,
                                          ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
                                          a_property,
                                          &gatts_demo_char2_val, NULL);
    if (add_char_ret)
    {
        ESP_LOGE(GATTS_TAG, "add char2 failed, error code =%x", add_char_ret);
    }
    break;

Steps to reproduce.

  1. Use The example esp\v5.2.1\esp-idf\examples\bluetooth\bluedroid\ble\gatt_server
  2. use function esp_ble_gatts_add_char() to add a new cha failed

Debug Logs.

No response

More Information.

No response

Dylanliacc avatar May 01 '24 11:05 Dylanliacc

What value does the function return when esp_ble_gatts_add_char is called? What is the status of the "ESP_GATTS_ADD_CHAR_EVT" event reported when add char fails? It looks like the value of "char_uuid_write" is incorrect image

esp-zhp avatar May 06 '24 02:05 esp-zhp

This is not the main question, I filled it in casually .The main problem is that when adding the second characteristic value, the system does not report any errors, but the Bluetooth client does not show that the addition was successful.

Dylanliacc avatar May 07 '24 03:05 Dylanliacc

The code you provided isn't complete. I suspect that the parameter "num_handle" you set when calling "esp_ble_gatts_create_service" is incorrect. Please review and set the correct num_handle. image

esp-zhp avatar May 07 '24 08:05 esp-zhp

The test on my end is fine; this is an example I wrote.

gatts_demo.zip

image

esp-zhp avatar May 07 '24 08:05 esp-zhp

got it ! I succeeded according to your help

Dylanliacc avatar May 08 '24 09:05 Dylanliacc