BLE: How to add multiple characteristics in one service?
Posted: Thu Nov 22, 2018 5:28 pm
Hi.
I need to create custom 128bit service with some characteristics (which will be 128 bits too)
As basic I'm using this https://github.com/espressif/esp-idf/bl ... tts_demo.c
I have sucessfully created custom 128bit service.
But when I'm trying add 2nd characteristic I'm facing this error:
My code part in gatts_profile_a_event_handler()
Please give me advice how should I create it.
I need to create custom 128bit service with some characteristics (which will be 128 bits too)
As basic I'm using this https://github.com/espressif/esp-idf/bl ... tts_demo.c
I have sucessfully created custom 128bit service.
But when I'm trying add 2nd characteristic I'm facing this error:
- [2018-11-22_18:41:57][0;32mI (87) BTDM_INIT: BT controller compile version [8353b1b]
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (88) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE[0m
- [2018-11-22_18:41:57][0;32mI (154) phy: phy_version: 3960, 5211945, Jul 18 2018, 10:40:07, 0, 0[0m
- [2018-11-22_18:41:57][0;32mI (333) BLE: ESP_GATTS_REG_EVT_A[0m
- [2018-11-22_18:41:57][0;32mI (334) BLE: REGISTER_APP_EVT, status 0, app_id 0
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;31mE (335) BT_BTC: btc128_to_bta_uuid: Unknown UUID length 0![0m
- [2018-11-22_18:41:57][0;31mE (339) BT_BTC: btc128_to_bta_uuid: Unknown UUID length 0![0m
- [2018-11-22_18:41:57][0;32mI (345) BLE: ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT[0m
- [2018-11-22_18:41:57][0;32mI (350) BLE: ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT[0m
- [2018-11-22_18:41:57][0;32mI (356) BLE: CREATE_SERVICE_EVT, status 0, service_handle 40
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;31mE (380) BT_GATT: Active Service Found [0m
- [2018-11-22_18:41:57][0;31mE (382) BT_GATT: Duplicate Service start - Service already started[0m
- [2018-11-22_18:41:57][0;32mI (389) BLE: ESP_GAP_BLE_ADV_START_COMPLETE_EVT[0m
- [2018-11-22_18:41:57][0;32mI (394) BLE: SERVICE_START_EVT_A, status 0, service_handle 40
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (401) BLE: ESP_GATTS_ADD_CHAR_EVT_A[0m
- [2018-11-22_18:41:57][0;32mI (405) BLE: ADD_CHAR_EVT, status 0, attr_handle 42, service_handle 40
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (413) BLE: the gatts demo char length = 3
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (417) BLE: prf_char[0] =11
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (421) BLE: prf_char[1] =22
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (425) BLE: prf_char[2] =33
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (429) BLE: SERVICE_START_EVT_A, status 133, service_handle 40
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (435) BLE: ESP_GATTS_ADD_CHAR_EVT_A[0m
- [2018-11-22_18:41:57][0;32mI (440) BLE: ADD_CHAR_EVT, status 133, attr_handle 0, service_handle 40
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (447) BLE: the gatts demo char length = 0
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (453) BLE: ESP_GATTS_ADD_CHAR_DESCR_EVT_A[0m
- [2018-11-22_18:41:57][0;32mI (457) BLE: ADD_DESCR_EVT, status 0, attr_handle 43, service_handle 40
- [2018-11-22_18:41:57][0m
- [2018-11-22_18:41:57][0;32mI (465) BLE: ESP_GATTS_ADD_CHAR_DESCR_EVT_A[0m
- [2018-11-22_18:41:57][0;32mI (470) BLE: ADD_DESCR_EVT, status 133, attr_handle 0, service_handle 40
- [2018-11-22_18:41:57][0m
- case ESP_GATTS_CREATE_EVT:
- ESP_LOGI(BLE_TAG, "CREATE_SERVICE_EVT, status %d, service_handle %d\n", 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.len = ESP_UUID_LEN_16;
- gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A;
- 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,
- ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
- a_property,
- &gatts_demo_char1_val, NULL);
- if (add_char_ret){
- ESP_LOGE(BLE_TAG, "add char failed, error code =%x",add_char_ret);
- }
- // add 2nd characteristic
- 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 = 0xDD01;
- 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;
- 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,
- ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
- a_property,
- &gatts_demo_char1_val, NULL);
- if (add_char_ret){
- ESP_LOGE(BLE_TAG, "add char failed, error code =%x",add_char_ret);
- }
- break;