微信小程序与RSL10蓝牙双向通信
本帖最后由 dql2016 于 2021-6-29 10:47 编辑<p><span style="font-size:16px;">连接成功后,RSL10采集的数据用通知的方式发送给微信小程序,之前一直卡在微信小程序无法发送数据给RSL10,经过摸索发现将ble_custom.c中的写特征值的读权限去掉就ok了,修改如下所示:</span></p>
<pre>
<code class="language-cpp">/* ----------------------------------------------------------------------------
* 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 = CS_SVC_UUID;
const struct gattm_att_desc att =
{
/* Attribute Index= Attribute properties: UUID,
* Permissions,
* Max size,
* Extra permissions */
/* TX Characteristic */
= ATT_DECL_CHAR(),
= ATT_DECL_CHAR_UUID_128(CS_CHARACTERISTIC_TX_UUID,
PERM(RD, ENABLE) | PERM(NTF, ENABLE),
CS_TX_VALUE_MAX_LENGTH),
= ATT_DECL_CHAR_CCC(),
= ATT_DECL_CHAR_USER_DESC(CS_USER_DESCRIPTION_MAX_LENGTH),
/* RX Characteristic */
= ATT_DECL_CHAR(),
/* = 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),*/
//只具备写权限
= ATT_DECL_CHAR_UUID_128(CS_CHARACTERISTIC_RX_UUID,
PERM(WRITE_REQ, ENABLE)
| PERM(WRITE_COMMAND, ENABLE),
CS_RX_VALUE_MAX_LENGTH),
= ATT_DECL_CHAR_CCC(),
= 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, &svc_uuid, ATT_UUID_128_LEN);
for (unsigned int i = 0; i < CS_IDX_NB; i++)
{
memcpy(&req->svc_desc.atts<i>, &att<i>,
sizeof(struct gattm_att_desc));
}
/* Send the message */
ke_msg_send(req);
}</i></i></code></pre>
<div class="parsedown-markdown"><span style="font-size:16px;">微信小程序接收的蓝牙数据是16进制的字符串形式,需要做一下转换才能正常显示,微信小程序发送给RSL10的数据直接在主循环读出来即可。至此,微信小程序和RSL10通过蓝牙双向收发数据就调通了,后面就是完善一下小程序的功能,例如给设备改名字启动后自动绑定设备;增加数据库存储数据,然后进行曲线图表的展示。</span></div>
<p><i><i><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=11v411H7f1&page=1" style="background:#eee;margin-bottom:10px;" width="750"></iframe><br />
</i></i></p>
<p>恭喜楼主又攻克一个难题,也感谢避坑分享!</p>
<p>恭喜楼主</p>
<p>这个要学习一下</p>
页:
[1]