Hi,
I need to send BLE notifications to the central from the peripheral application in case of a characteristic value change. What is the API that needs to be used for the same? Is there an example available anywhere?
Also, how to handle write on CCC descriptor to enable or disable the indications (GATT_CCC_START_IND, GATT_CCC_STOP_NTFIND) in the application itself.
谢谢,
hrishikesh.
Device:
Hi dhrishi,
您可以检查BLE_APP_PERIANTAL示例以检查如何发送通知。该示例使用Custs配置文件来发送通知,但您可以转到配置文件的实际发送数据,并检查配置文件如何发送实际数据。用于配置文件的命令是custs1_val_ntf_req,触发的回调是custs1_val_ntf_req_handler()函数。发送通知的实际命令是prf_server_send_event()函数(在更改数据库Attmdb_att_set_value()中更改值后调用该命令,因为它发送数据库中的值)。
关于你提到的第二个问题,我不确定我的联合国derstand the question i suppose that you mean how to catch the event where the central actually writes to the CCC characteristic, the callback that triggers when a writing event comes is the GATTC_WRITE_CMD_IND callback and the profile will have to check the value send and write it in the database, you can check how the profile is handling this in the gattc_write_cmd_ind_handler().
Thaks MT_dialog
Hi,
Thanks for your reply.
Note: I have created the GATT database in the application using data from the UART commands from an external MCU using KE_MSG_ALLOC commands (TASK_ATTM and TASK_APP) In short, no standard profile or custom profile provided by the Dialog SDK is used by me.
I checked prf_server_send_event() function. The first parameter to this is: prf_env_struct *p_env
我在这里发送什么?您是否希望我在本地创建一个类型的prf_env_struct和填充其成员的变量。在那种情况下,有什么价值:
appid:??
PRFID:??
conidx: current connection id ?
Hi dhrishi,
The prf_server_send_event() function essentially uses the GATTC_SEND_EVT_CMD with the corresponding parameters. Most of the parameters are held in the examples in a structure that holds available information for the profile used, the app_id is the TASK_APP, the profile id is the profile id that issues the command, in that case is the CUSTS1_TASK and the conidx is the connection index of the current connection. Most of those information populate the structure upon enabling the custs1 profile. In your case you can get the conidx from the app_env structure, and since you have no profile layer you should be able to use TASK_APP as a prfid.
谢谢mt_dialog.
Hi,
当在本地更新特征值时,我尝试了以下代码发送零长度指示(BLE连接处于活动状态)。
虽然,我没有看到中央/控制器发送读取请求以获取新值。这有什么问题?
By default, does the indicate request send the new value too? If yes, I don't want that. I want to send a zero length indication as required by the central side. Is that possible? If yes, how do we do that?
uint16_t handle; /* Handle is the handle of the characteristic whose value has changed */
struct gattc_send_evt_cmd *req = KE_MSG_ALLOC(GATTC_SEND_EVT_CMD,
KE_BUILD_ID(TASK_GATTC, app_connection_idx), TASK_APP, gattc_send_evt_cmd);
req-> req_type = gattc_indicate;
req-> handle = handle;
ke_msg_send(req);
上面的代码中需要哪些更改以发送零长度指示?
Hi dhrishi,
To start with the indications are initiated from the peripheral (just like notifications but with application confirmation when the value reaches the peripheral) and not the central, the peripheral can only send indications towards the central and not the other way around, so in order to send an indication from a peripheral you just have to send that message from your application, the central doesn't read the indicatable value, it is just the peripheral that indicates that value to the central, the central just confirms that he received the message send from the peripheral.
The GATTC_SEND_EVT_CMD message when instructed to send an indication you will have fill in the handle of the attribute that you would like to send, if the value of the characteristic is zero length, i dont see any problem in sending that.
I did the following test, i ve set the "Indicatable" characteristic, in the ble_app_peripheral, to have the size of 0, and created a timer callback that sends a CUSTS1_VAL_IND_REQ periodically other than that i left the project as is, so whenever i enabled the indications i could see on the sniffer that the indication left the device properly and the central was sending back the proper confirmation.
谢谢mt_dialog.
Hi,
Thanks for your reply. I already got it working and I did it exactly the same way you mentioned. Before sending the indication, I set the corresponding characteristic value length as zero. As a result, a zero length indication is sent and it works fine. Thanks for your help.
谢谢,
hrishikesh.