How to add multi characteristics into one BLE service

wilkins_yuan
Posts: 1
Joined: Sat Feb 10, 2018 9:45 am

How to add multi characteristics into one BLE service

Postby wilkins_yuan » Sat Feb 10, 2018 9:55 am

I'm developing one BLE peripheral device. When I add more than one characteristics into my services, the event return status is always ESP_GATT_ERROR.
The first characteristics is successfully added after receive ESP_GATTS_CREATE_EVT. When I get the success return of the 1st char ESP_GATTS_ADD_CHAR_EVT , I use esp_ble_gatts_add_char to add the second one, but it always fail.
Please help me to check where is wrong .

static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
ESP_LOGE(GATTS_TAG, "profile A Event %d, gatts_if %d", event, gatts_if);
switch (event) {
//.................................
case ESP_GATTS_CREATE_EVT:
ESP_LOGI(GATTS_TAG, "CREATE_SERVICE_EVT, status %d, service_handle %d\n", param->create.status, param->create.service_handle);
gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].service_handle = param->create.service_handle;
gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].char_uuid.len = ESP_UUID_LEN_16;
gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A;

esp_ble_gatts_start_service(gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].service_handle);

esp_ble_gatts_add_char(gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].service_handle, &gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].char_uuid,
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_NOTIFY,
&gatts_demo_char1_val, NULL);

current_adding_char = CHAR_WRITY_FF01;
break;
case ESP_GATTS_ADD_INCL_SRVC_EVT:
break;
case ESP_GATTS_ADD_CHAR_EVT: {
uint16_t length = 0;
const uint8_t *prf_char;

ESP_LOGI(GATTS_TAG, "ADD_CHAR_EVT, status %d, attr_handle %d, service_handle %d\n",
param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle);
if(current_adding_char == CHAR_WRITY_FF01)
{
gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].char_notify_uuid.len = ESP_UUID_LEN_16;
gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].char_notify_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_B;

esp_ble_gatts_add_char(gl_profile_tab_yh[PROFILE_A_APP_ID_ADV].service_handle, &gl_profile_tab_yh[PROFILE_A_APP_ID].char_notify_uuid,
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_NOTIFY,
&gatts_demo_char2_val, NULL);
current_adding_char = CHAR_NOTIFY_FF02;
}
break;
}


The result always is :
[0;31mE (532) GATTS_DEMO: Event 7, gatts_if 3[0m
[0;31mE (532) GATTS_DEMO: profile A Event 7, gatts_if 3[0m
[0;32mI (542) GATTS_DEMO: CREATE_SERVICE_EVT, status 0, service_handle 40
[0m
[0;31mE (552) GATTS_DEMO: Event 12, gatts_if 3[0m
[0;31mE (552) GATTS_DEMO: profile A Event 12, gatts_if 3[0m
[0;32mI (562) GATTS_DEMO: SERVICE_START_EVT, status 0, service_handle 40
[0m
[0;31mE (562) GATTS_DEMO: Event 9, gatts_if 3[0m
[0;31mE (572) GATTS_DEMO: profile A Event 9, gatts_if 3[0m
[0;32mI (572) GATTS_DEMO: ADD_CHAR_EVT, status 0, attr_handle 42, service_handle 40
[0m
[0;31mE (582) GATTS_DEMO: Event 9, gatts_if 3[0m
[0;31mE (592) GATTS_DEMO: profile A Event 9, gatts_if 3[0m
[0;32mI (592) GATTS_DEMO: ADD_CHAR_EVT, status 133, attr_handle 0, service_handle 40
[0m

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], davidv and 127 guests