本帖最后由 dql2016 于 2021-6-29 10:47 编辑
连接成功后,RSL10采集的数据用通知的方式发送给微信小程序,之前一直卡在微信小程序无法发送数据给RSL10,经过摸索发现将ble_custom.c中的写特征值的读权限去掉就ok了,修改如下所示:
/* ----------------------------------------------------------------------------
* Function : void CustomService_ServiceAdd(void)
* ----------------------------------------------------------------------------
* Description : Send request to add custom profile into the attribute
* database.Defines the different access functions
* (setter/getter commands to access the different
* characteristic attributes).
* Inputs : None
* Outputs : None
* Assumptions : None
* ------------------------------------------------------------------------- */
void CustomService_ServiceAdd(void)
{
struct gattm_add_svc_req *req =
KE_MSG_ALLOC_DYN(GATTM_ADD_SVC_REQ,
TASK_GATTM, TASK_APP,
gattm_add_svc_req,
CS_IDX_NB * sizeof(struct gattm_att_desc));
const uint8_t svc_uuid[ATT_UUID_128_LEN] = CS_SVC_UUID;
const struct gattm_att_desc att[CS_IDX_NB] =
{
/* Attribute Index = Attribute properties: UUID,
* Permissions,
* Max size,
* Extra permissions */
/* TX Characteristic */
[CS_IDX_TX_VALUE_CHAR] = ATT_DECL_CHAR(),
[CS_IDX_TX_VALUE_VAL] = ATT_DECL_CHAR_UUID_128(CS_CHARACTERISTIC_TX_UUID,
PERM(RD, ENABLE) | PERM(NTF, ENABLE),
CS_TX_VALUE_MAX_LENGTH),
[CS_IDX_TX_VALUE_CCC] = ATT_DECL_CHAR_CCC(),
[CS_IDX_TX_VALUE_USR_DSCP] = ATT_DECL_CHAR_USER_DESC(CS_USER_DESCRIPTION_MAX_LENGTH),
/* RX Characteristic */
[CS_IDX_RX_VALUE_CHAR] = ATT_DECL_CHAR(),
/*[CS_IDX_RX_VALUE_VAL] = ATT_DECL_CHAR_UUID_128(CS_CHARACTERISTIC_RX_UUID,
PERM(RD, ENABLE) | PERM(WRITE_REQ, ENABLE)
| PERM(WRITE_COMMAND, ENABLE),
CS_RX_VALUE_MAX_LENGTH),*/
//只具备写权限
[CS_IDX_RX_VALUE_VAL] = ATT_DECL_CHAR_UUID_128(CS_CHARACTERISTIC_RX_UUID,
PERM(WRITE_REQ, ENABLE)
| PERM(WRITE_COMMAND, ENABLE),
CS_RX_VALUE_MAX_LENGTH),
[CS_IDX_RX_VALUE_CCC] = ATT_DECL_CHAR_CCC(),
[CS_IDX_RX_VALUE_USR_DSCP] = ATT_DECL_CHAR_USER_DESC(CS_USER_DESCRIPTION_MAX_LENGTH),
};
/* Fill the add custom service message */
req->svc_desc.start_hdl = 0;
req->svc_desc.task_id = TASK_APP;
req->svc_desc.perm = PERM(SVC_UUID_LEN, UUID_128);
req->svc_desc.nb_att = CS_IDX_NB;
memcpy(&req->svc_desc.uuid[0], &svc_uuid[0], ATT_UUID_128_LEN);
for (unsigned int i = 0; i < CS_IDX_NB; i++)
{
memcpy(&req->svc_desc.atts, &att,
sizeof(struct gattm_att_desc));
}
/* Send the message */
ke_msg_send(req);
}
微信小程序接收的蓝牙数据是16进制的字符串形式,需要做一下转换才能正常显示,微信小程序发送给RSL10的数据直接在主循环读出来即可。至此,微信小程序和RSL10通过蓝牙双向收发数据就调通了,后面就是完善一下小程序的功能,例如给设备改名字启动后自动绑定设备;增加数据库存储数据,然后进行曲线图表的展示。
|