跳到主要内容

Can't read charateristic value from iPhone app (LightBlue)

4 years ago

Can't read charateristic value from iPhone app (LightBlue)

Posted bymuxf0分 8 replies
0 upvotes

Hi dialog team,

I am newcomer in BLE and trying to run the ble_app_peripheral project on DA14580 based on SDK5.0.4. (EVK Pro)The central device is iPhone app LightBlue. My final goal is reading accelerator sensor value controlled by iPhone.

作为第一步,我想看看我是否可以在DA14580上捕获事件,要做它,在回调函数中设置了几个断点,如gattc_write_cmd_ind_handler,custs1_val_ind_req_handler和custs1_val_ntf_req_handler在文件custs1_task.c中。

After that, If I push "write new value" in LightBlue, then I can see the program stops in the gattc_write_cmd_ind_handler function which is also expected. But if I push "read" in LightBlue, nothing happens in the program. LightBlue shows also "no value" What's the reason?

I know there are already several threads discussed about this issue, for example

- using notification instead of read, because read access directly BLE stack
- SDK 5.0.4 will fix it
- take ble_app_peripheral as reference
and so on

I tried all these, but no success. So

1.您能告诉我哪个示例代码可以从LightBlue处理“读取”
2. If there is no such example, would you please tell me which steps should I then do? A little more details will be very helpful for me
3. Is LightBlue the right mobile app for testing "read" ? If not, which app would you recommend me?

Thank you very much

anton

4 years ago

muxf 0分

I read the release notes of SDK5.0.4 and find out that GATTC_READ_CMD_IND is now also supported in SDK 5.0.4. So I tried to do the following analog to GATTC_WRITE_CMD_IND:

1. add handler definition for GATTC_READ_CMD_IND in custs1_task.c
{GATTC_READ_CMD_IND, (ke_msg_func_t)gattc_read_cmd_ind_handler}

2.在Custs1_task.c中实现gattc_read_cmd_ind_handler
In this step I just send the custs1_val_read_ind message (analog to custs1_val_write_ind ) with message ID CUSTS1_VAL_READ_IND

3. I then implement the switch case for reading the 2nd ADC value in user_catch_rest_hndl function in the file user_peripheral.c
...
case CUSTS1_VAL_READ_IND:
{
struct musts1_val_read_ind const * msg_param =(struct custs1_val_read_ind const *)(param);
交换机(msg_param->句柄)
{
case CUST1_IDX_ADC_VAL_2_VAL:
int sta=0;
休息;
default:
休息;
}
}休息;
...
4. I set the break point at int sta=0, and then run LightBlue to put the "read again" of the ADC 2nd Value. (The connection between iPhone and DA14580 can be established well) As already mentioned above, at this point, I don't see the program jump to the break point, and "no value" shows in LightBlue.
But for "Write" I can see that the program jumps into the write handler, and without break point it can then switch on/off LED.

所以它告诉我,Gattc_Read_cmd_ind仍然无法正常工作。“读”处理有什么问题?你能给我更多细节吗?
谢谢

anton

4 years ago

JK_Dialog 0分

Hi,

Please reference RW-BLE-GATT-IS. GATTC_READ_CMD_IND is not a valid command. Please refer to page 21 of Interface specification and use GATTC_READ_IND for your callback.

Additionally, nothing is written to the value characteristics in the barebone version of the ble_app_peripheral. However, the description attributes are written to and read by the Light Blue application. On the application's connection, the iPhone will read all of the description characteristics, and you should get a callback here.

Try substituting that small change up there, then on the 580, try to change the value characteristic and verifying that you can read the value.

Use this handler for setting the value:

静态INT CUSTS1_VAL_SET_REQ_HANDLER(KE_MSG_ID_T CONST MSGID,
struct musts1_val_set_req const * param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)

4 years ago

muxf 0分

Hi,
according to your suggestion, I tried to find out firstly where a description characteristic will be read, but no success:

- 仅在整个项目中搜索“cust1_adc_val_2_user_desc”--->仅在客户数据库定义中显示(user_custs1_def.c)

- 在整个项目中搜索“gattc_read_ind”--->“gattc_read_ind”可以通过文件prf_utils.c中的函数prf_client_att_info_rsp()调用
--->但它(prf_client_att_info_rsp())永远不会被其他函数调用。

- set break point in the function prf_client_att_info_rsp() and then run Light Blue, the connection can be established well, but the program doesn't jump
into the function prf_client_att_info_rsp()

Summary:

到目前为止,我掌握了你的帮助
- GATTC_READ_IND is the event after "read" activated by Light Blue
- custs1_val_set_req_handler() should be used to set the value
但是在BLE_APP_PERITELAL项目的帮助下,我仍然无法捕获读流

您是否会告诉我浅蓝色和DA14580之间的读取流程有什么细节,详细说明特征?

谢谢

4 years ago

muxf 0分

It seems that the read request from Light Blue never be delivered to the DA14580 user application layer, that's why I can't catch such events. (but why it is possible for write? ) If it is true, would you please tell me what is the work flow for me to deal with such read request form central device in user application layer on the peripheral side? I already spent one week in this issue, please help me to fix it. Thank you very much

anton

4 years ago

JK_Dialog 0分

I verified that I can set the ADC_VAL2_CHAR, and I can read it from the lightBlue OS using the custs1_val_set_req.

我还确认了您发现的内容,关于未传递到应用程序层的消息。我正在挖掘这个,一旦找到解决方案就会回复。

4 years ago

muxf 0分

我不知道如何使用custs1_val_set_req(),但在研究DSP示例之后,我还确认了一个可以使用custs1_val_set_req设置值。然后可以通过闪烁读取该值。我正在等待您的解决方案,了解用户应用层的读取指示。谢谢

4 years ago

JK_Dialog 0分

抱歉延迟,只是在Thsi上获得一些答案。此外,我可以问你为什么需要这个功能的申请吗?此外,您是否读到了软件发行说明中的​​读取,描述了对事件注册?以下是如何实现此功能的基本原则:

***********************************************************************************************************************

介绍ATTS_READ_REQ_IND消息。该消息包含对等设备请求读取的属性的句柄。
要求此机制的任务通常使用dg_register_task_for_read_request()C API在DB创建时间下注册ATTS_READ_REQ_IND消息。
Upon reception of the ATTS_READ_REQ_IND message the task can modify the ATT DB and then it must reply by calling dg_atts_read_cfm(). There are two use cases:
任务决定请求请求有效,(可选地)修改DB中的值,最终通过在DG_atts_read_cfm()的status_code参数中传递att_err_no_error来回复。这导致将ATT读取响应声发送到对等设备。
任务决定读取请求无效,并通过将ATT错误代码传递给DG_Atts_Read_cfm()来响应。这导致将ATT错误响应发送给对等设备。

4 years ago

muxf 0分

我想展示我们的客户,即读取传感器数据可以由他的iPhone控制。我虽然因为写入gattc_write_cmd_ind,但是必须有读取的模拟指示。发布说明中提到的部分似乎比gattc_write_cmd_ind更复杂,因此我不确定它是否是正确的方法来做。谢谢你的提示,租约我知道现在释放的部分是正确的方法。票可以关闭。