dvacos 发表于 2024-9-27 19:11

【NUCLEO-WB09KE测评】四、修改广播名 与 新增自定义服务

本帖最后由 dvacos 于 2024-9-27 19:19 编辑

<div><strong><span style="font-size:18px;">一 熟悉例程</span></strong></div>

<div>BLE_p2pServer直接编译烧录后,确认广播名 、服务、特征等。</div>

<div>&nbsp;</div>

<div>广播内容,按照SIG规范填写厂商码,可以直接识别出是ST的蓝牙IC</div>

<div></div>

<div>&nbsp;</div>

<div>广播原始数据</div>

<div></div>

<div>&nbsp;</div>

<div>自定义服务 与 特征</div>

<div></div>

<div>&nbsp;</div>

<div><span style="font-size:18px;"><strong>二 修改广播名</strong></span></div>

<div>&nbsp;</div>

<div>查阅代码后发现,广播数据由下图传入协议栈</div>

<div></div>

<div>&nbsp;</div>

<div>直接修改广播数组即可修改广播名</div>

<div></div>

<div>&nbsp;</div>

<div>实验结果如下,成功修改广播名</div>

<div></div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div><span style="font-size:18px;"><strong>三 添加自定义服务</strong></span></div>

<div>&nbsp;</div>

<div>新增第二个服务</div>

<div></div>

<div>&nbsp;</div>

<div>使用短UUID,并新建2个特征</div>

<div></div>

<div>&nbsp;</div>

<div>服务1 的配置</div>

<div>服务1用于接收数据,所以配置 WRITE(写) 、WRITE NO RESP(写不回复)2个特征用于接收手机下发的数据</div>

<div></div>

<div>&nbsp;</div>

<div>服务2 的配置</div>

<div>服务2用于上报数据,所以配置NOTIFY (弹出)特征</div>

<div></div>

<div>&nbsp;</div>

<div>实验</div>

<div>烧录后上电查看LOG提示初始化新增的服务失败,经过一同艰难的查阅之后终于解决,方法如下:</div>

<div></div>

<div>&nbsp;</div>

<div>&nbsp;</div>

<div>修改服务的上限值,来添加新的服务</div>

<div>原本的服务1使用6个</div>

<div></div>

<div>新增的服务2也是使用6个</div>

<div></div>

<div>所以将服务属性修改为12个</div>

<div></div>

<div>&nbsp;</div>

<div><span style="font-size:18px;"><strong>四 实验结果</strong></span></div>

<div>Log显示添加成功!</div>

<div></div>

<div>&nbsp;</div>

<div>手机APP确认广播名修改(右上角)、添加新自定义服务(红框)成功!!</div>

<div></div>

<div>&nbsp;</div>

<p><!--importdoc--></p>

秦天qintian0303 发表于 2024-9-28 13:40

<p>广播内容还是很重要的,对于产品设计是否需要连接获取一般就根据这个识别</p>

wangerxian 发表于 2024-9-29 17:43

<p>广播名可以动态修改吗?</p>

dvacos 发表于 2024-9-29 17:59

wangerxian 发表于 2024-9-29 17:43
广播名可以动态修改吗?

<p>没研究噢,但是肯定可以做的。修改广播任何一家的蓝牙芯片都能做吧,大不了关了再开</p>

慕容雪花 发表于 2024-9-30 13:04

<p>感谢大佬分享!太棒了</p>

sujingliang 发表于 2024-10-8 13:26

<p>赞</p>

<p>学习了:</p>

<p>如果定义多个特征值报0x87错,虽然头文件定义是内寸不足</p>

<p>#define BLE_STATUS_OUT_OF_MEMORY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((tBleStatus)(0x87))</p>

<p>但是调整CFG_BLE_NUM_GATT_ATTRIBUTES可以解决</p>

<p>&nbsp;</p>

<p><b>CFG_BLE_NUM_GATT_ATTRIBUTES</b><br />
CFG_BLE_NUM_GATT_ATTRIBUTES must be &ge;<b> 2</b>.<br />
<b>Parameter Description:</b><br />
Maximum number of Attributes that can be stored in the GATT database<br />
When a GATT characteristic is added to the database a minimum of 2 attribute records are needed: one for the characteristic declaration and one for the characteristic value. On top of this, additional records may be needed based on the characteristic properties, in particular:<br />
- If the characteristic has the notify or indicate property set, then one additional attribute record is needed.<br />
- If the characteristic has the broadcast property set, then one additional attribute record is needed.<br />
- If the characteristic has the extended property set, then one additional attribute record is needed.<br />
In summary, one characteristic may need from 2 to 5 attribute records depending on the characteristic properties.</p>
页: [1]
查看完整版本: 【NUCLEO-WB09KE测评】四、修改广播名 与 新增自定义服务