[已解决] 如何创建Characteristic User Description

ming191
Posts: 46
Joined: Mon May 31, 2021 6:27 am

[已解决] 如何创建Characteristic User Description

Postby ming191 » Thu Jun 24, 2021 3:29 am

工程师,你好。在ESP_GATTS_ADD_CHAR_EVT事件当中,可以利用
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;

esp_err_t add_descr_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);

可以产生client Characteristic Configuration
UUID:0x2902.

但是我看到其他服务还有一个这样的描述,
characteristic User Description
UUid:0x2901

我尝试了很多次,将ESP_GATT_UUID_CHAR_CLIENT_CONFIG改为ESP_GATT_UUID_CHAR_DESCRIPTION,就可以出现characteristic User Description. 但是我不明白,怎么让这两个特征值描述符同时存在?能否举下例子。
Attachments
2.png
2.png (37.99 KiB) Viewed 3899 times
Last edited by ming191 on Fri Jun 25, 2021 2:59 am, edited 1 time in total.

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: 如何创建Characteristic User Description

Postby ESP_XuLZ » Thu Jun 24, 2021 1:54 pm

原因是创建 Service 时 handle 数目不够用, 比如在创建 service B 时 handle 数目为GATTS_NUM_HANDLE_TEST_B =4
Service 声明占一个,Characteristic 声明和Characteristic 值分别一个,描述符再占一个,所以就满了,再增加一个描述符 没有handle 分配了就创建不成功了,所以把 GATTS_NUM_HANDLE_TEST_B 增大就可以了

建议你使用 gatt_server_service_table 中的方法,以表格形式创建Service 、Characteristic 和描述符,更加简单和清晰

ming191
Posts: 46
Joined: Mon May 31, 2021 6:27 am

Re: 如何创建Characteristic User Description

Postby ming191 » Fri Jun 25, 2021 1:04 am

明白你的意思了,非常谢谢。但是我还有一个小疑问:
1.在unkown Characteristic 最右边的按钮,应该就是CCCD配置符,不断轮流点击,在Clinet Characteristic Configuration的value就是可以轮流显示 Notifications and indications disable 或者 Notifications enable .在Clinet Characteristic Configuration ,右边只有一个向下的箭头,应该是读的意思。我程序应该要返回来什么,才能显示 Notifications and indications disable 或者 Notifications enable .我学程序这样写是不行。
rsp.attr_value.len =15;
for(int testNum = 0; testNum < 15; ++testNum)
{
rsp.attr_value.value[testNum]= testNum%0xff;
}
esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
ESP_GATT_OK, &rsp);
我收到是00,01,02一直到0E。
而例程是这样发的,
uint8_t notify_data[15];
for (int i = 0; i < sizeof(notify_data); ++i)
{
notify_data = i%0xff;
}
//the size of notify_data[] need less than MTU size
esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
sizeof(notify_data), notify_data, false);
我发现唯一不同的就是,发送接口不一样。所以这点不是很明白,我应该怎么改。
Attachments
3.png
3.png (43.91 KiB) Viewed 3841 times

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: 如何创建Characteristic User Description

Postby ESP_XuLZ » Fri Jun 25, 2021 2:38 am

1、显示 Notifications and indications disable 是nrf connect APP 自己处理的,使用esp_ble_gatts_send_indicate回复其他值它也只会显示这两条指示
2、read 事件没办法显示这个字符串,它是以hex形式显示的

ming191
Posts: 46
Joined: Mon May 31, 2021 6:27 am

Re: 如何创建Characteristic User Description

Postby ming191 » Fri Jun 25, 2021 2:58 am

好的,非常多谢你们。我今天好好研究这个sever_table.谢谢。

Who is online

Users browsing this forum: No registered users and 39 guests