蓝牙控制板底层通信协议V2版
<h1><center>蓝牙底层通信协议</center></h1>
<h2>注意事项:</h2>
<p>1、不发和发0意义不同。</p>
<h2>一、广播数据</h2>
<table>
<thead>
<tr>
<th>LEN</th>
<th>TYPE</th>
<th>VALUE</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>0x01</td>
<td>0x06</td>
<td>蓝牙特性</td>
</tr>
<tr>
<td>3</td>
<td>0x03</td>
<td>0xF0FF</td>
<td>蓝牙主服务</td>
</tr>
<tr>
<td>9</td>
<td>0xFF</td>
<td>0x0101XXXXXXXXXXXXXX</td>
<td>“0101”为厂商标识,“xx..xx”为MAC地址</td>
</tr>
<tr>
<td>10</td>
<td>0x08</td>
<td>0xXXXXXX…</td>
<td>广播名称,10byte</td>
</tr>
</tbody>
</table>
<p><strong> 注:Mac地址为系统识别设备使用,iOS系统mac为加密地址所以不能直接用mac定位。 </strong></p>
<h2>二、应用服务</h2>
<pre><code>服务ID:00000001-0000-1000-8000-00805F9B34FB
characteristicId-write:000284CF-F7E3-55B4-6C4C-9FD140100A16
characteristicId-notify:000384CF-F7E3-55B4-6C4C-9FD140100A16</code></pre>
<h2>三、设备控制过程</h2>
<ol>
<li>扫描通过“主服务”过滤扫描设备。</li>
<li>通过“广播”数据中的mac定位需要连接设备的地址(ios为加密地址,Android为设备mac地址)。</li>
<li>连接设备。(3s内认证设备自动断开)</li>
<li>发现应用服务。</li>
<li>开启characteristicId-notify特征监听。</li>
<li>接收到设备发送的通讯加密参数。</li>
<li>使用通讯加密参数向设备发送指令。</li>
</ol>
<h2>四、设备发送秘钥解析</h2>
<p><strong>当主机与设备连接成功后在开启监听characteristicId-notify的情况下会收到设备的认证参数</strong></p>
<pre><code>认证参数:0x31584d5f6c63685776363338314635434241</code></pre>
<p><strong>ASCII对照:31=字符1 58=字符X 依次类推可得结果: </strong></p>
<pre><code>1XM_lock_v6381F5CBA</code></pre>
<p><strong><code>1</code>为流程ID:连接成功</strong></p>
<p><strong><code>XM_lock_v6</code> 为 10个字符长度的设备名称</strong></p>
<p><strong><code>381F5CBA</code> 为 8个字符长度的随机串,每次连接和断开会重置</strong></p>
<p><strong>取 <code>XM_lock_v6381F5CBA</code> 保存,用于后期交互验证【以下均称为认证串】 </strong></p>
<h2>五、流程2-指令发送</h2>
<p><strong>指令集:</strong></p>
<table>
<thead>
<tr>
<th>指令ID</th>
<th>响应数</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>20</td>
<td>2</td>
<td>读配置</td>
</tr>
<tr>
<td>21</td>
<td>2</td>
<td>开锁</td>
</tr>
<tr>
<td>24</td>
<td>1</td>
<td>改密码</td>
</tr>
<tr>
<td>25</td>
<td>1</td>
<td>改名字</td>
</tr>
<tr>
<td>26</td>
<td>1</td>
<td>查状态</td>
</tr>
<tr>
<td>27</td>
<td>1</td>
<td>写27</td>
</tr>
<tr>
<td>28</td>
<td>1</td>
<td>写28</td>
</tr>
<tr>
<td>29</td>
<td>1</td>
<td>读版本</td>
</tr>
<tr>
<td>2a</td>
<td>1</td>
<td>带参数的开锁</td>
</tr>
<tr>
<td>2b</td>
<td>1</td>
<td>带参数的关锁</td>
</tr>
</tbody>
</table>
<pre><code>默认密码“00000000” </code></pre>
<h3>读取锁的配置信息“20”:</h3>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/1bb055630e0665399183708c74557ecf" alt="" /></p>
<p><strong>第一次通知characteristicId-notify:<code>3330xxxxxxxxxxxxxxxxxxxx</code></strong></p>
<ul>
<li><strong>33 => 字符3</strong></li>
<li><strong>30 => 字符0</strong></li>
</ul>
<p><strong>3330=>30 表示对20的回复</strong>
<strong>如果:xxxx….为0则密钥验证失败</strong></p>
<p><strong>第二次通知characteristicId-notify:<code>3338xxxxxxxx</code></strong></p>
<h3>开指令21</h3>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/58096250997046248c3a07d3aca7f4e6" alt="" /></p>
<p><strong> 第一次通知characteristicId-notify:转换为ASCII字符串<code>310d120003000300</code></strong>
(收到开锁指令,直接发送)</p>
<ul>
<li><strong>31 对 21 指令的回复</strong></li>
<li><strong>0D12 16进制电压mv</strong></li>
<li><strong>0003 16进制开锁次数</strong></li>
<li><strong>0003 电池剩余电量百分比</strong></li>
<li><strong>0 接收指令时的状态 [0关/1开]</strong></li>
<li><strong>0x30+(钥匙开锁<<2 |锁舌触发<<1 | 锁被锁定)</strong>(图片此处未更新)</li>
</ul>
<p><strong> 第二次通知characteristicId-notify:转换为ASCII字符串<code>310d120003000310</code></strong>
(开锁成功后,由锁状态中断触发。未检测到开锁或无开锁传感器,本次不会发送)
内容同第一次。</p>
<p><strong> 第三次通知characteristicId-notify:</strong>
(超时触发。)
内容同第一次。</p>
<p><strong> 对比收到的前两次回复的锁状态 </strong> </p>
<ul>
<li><strong>0->1 表示打开成功</strong></li>
<li><strong>0->0 表示打开失败</strong></li>
<li><strong>1->1 表示打开成功</strong></li>
</ul>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/fed0a69543130c77aad557c6c84db8e2" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/b74a1165d4a19c99f320b80036ed2261" alt="" /></p>
<p><strong>注意: 2a 定时器开,超时时间最大值为: 0x000fffff 单位: 秒</strong></p>
<p>--20220411修改:
1、更新版本号0x4040。
2、返回锁状态最后一位增加入户门控锁状态监控,值=0x30+(钥匙开锁<<2 |锁舌触发<<1 | 锁被锁定)
3、开锁返回又固定2次,改为2~3次。正常3次,未成功开锁返回2次。
--20220412修改:
1、增加电机锁锁舌关闭等待时间配置,非0按设置等待,==0则不自动关闭锁舌。
2、增加电机锁AB相交换参数,用来解决电机接口不统一导致的正反转相反问题。
3、增加电池电量及百分比计算三个参数:最大压差、最低电压、分压比。
4、失能,电机锁最小运行时间、重试次数、是否重试功能。
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=f44a628da696793ff50dcd2c84e108e3" alt="" /></p>