Skip to content
Li, Xizhi edited this page Oct 8, 2019 · 3 revisions

Welcome to the PluginBlueTooth wiki!

串口协议: 蓝牙串口模块说明

概述

蓝牙串口模块是电脑端与逻辑塔进行通信的模块。蓝牙串口模块包含一个蓝牙芯片和一个串口芯片。电脑需要安装串口驱动,通过串口控制该模块,进行收发蓝牙数据。模块的实际电路板如下图:

image

串口驱动

https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

串口控制

串口软件

串口调试软件在《串口调试软件》目录。

命令

电脑通过串口的命令行接口与串口模块交互,类似shell 控制终端。该模块所有支持的命令参考: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fstruct_nrf52%2Fstruct%2Fnrf52832.html&cp=3_1

image

注意:如果执行 gatt services 如果返回的UUID为0,应该再次执行 gatt services 。

控制示例: 电量和方块信息_串口调试

BLE app with command line interface example started.
Press Tab to view all available commands.
uart_cli:~$ 

uart_cli:~$ scan on
Scan started
<info> app: Scanning
uart_cli:~$ devices 
Device CB:51:62:B4:06:05 LOGITOW
uart_cli:~$ connect CB:51:62:B4:06:05
<info> app: CENTRAL: Connecting...
Connected to address: CB 51 62 B4 06 05 
<info> app: CENTRAL: Connected, handle: 0.
MTU changed successfully
Current MTU: 23
<info> app: Data length updated to 27 bytes.
uart_cli:~$ gatt services  CB:51:62:B4:06:05
<info> app: primary_services_discover offset:2 num:2 start handle:1 ,end:8
Connection parameters update success
<info> app: primary_services_discover offset:3 num:1 start handle:9 ,end:14
<info> app: primary_services_discover offset:4 num:1 start handle:15 ,end:65535
<info> app: on_read_rsp Services count: 4
Found service UUIDs: 
UUID: 1800 type: 0x1
UUID: 1801 type: 0x1
UUID: 0 type: 0x2
UUID: 0 type: 0x3
uart_cli:~$ gatt services  CB:51:62:B4:06:05
<info> app: primary_services_discover offset:2 num:2 start handle:1 ,end:8
<info> app: primary_services_discover offset:3 num:1 start handle:9 ,end:14
<info> app: primary_services_discover offset:4 num:1 start handle:15 ,end:65535
<info> app: on_primary_srv_discovery_rsp Services count: 4
Found service UUIDs: 
UUID: 1800 type: 0x1
UUID: 1801 type: 0x1
UUID: 1 type: 0x2
UUID: 4 type: 0x3
uart_cli:~$ gatt characteristics  CB:51:62:B4:06:05 4
Characteristic UUID: 5
Parameters:
broadcast: 0 read: 0 write_wo_resp: 1 write: 1 notify: 1
indicate: 0 auth_signed_wr: 0
<info> app: search start :1 ,end:7
<info> app: search start :8 ,end:8
<info> app: search start :9 ,end:14
<info> app: search start :15 ,end:65535
<info> app: handle_range start :18 ,end:65535
<info> app: on_characteristics_discovery_rsp count:1, offset:1 value_handle:17

Characteristic UUID: 6
Parameters:
broadcast: 0 read: 0 write_wo_resp: 1 write: 1 notify: 0
indicate: 0 auth_signed_wr: 0
<info> app: search start :1 ,end:7
<info> app: search start :8 ,end:8
<info> app: search start :9 ,end:14
<info> app: search start :15 ,end:65535
<info> app: handle_range start :21 ,end:65535
<info> app: on_characteristics_discovery_rsp count:1, offset:2 value_handle:20

<info> app: search start :1 ,end:7
<info> app: search start :8 ,end:8
<info> app: search start :9 ,end:14
<info> app: search start :15 ,end:65535
<info> app: handle_range start :21 ,end:65535
<info> app: on_characteristics_discovery_rsp count:0, offset:2 value_handle:20

Number of characteristics: 2
uart_cli:~$ gatt write  CB:51:62:B4:06:05
unknown parameter: CB:51:62:B4:06:05
uart_cli:~$ gatt write  CB:51:62:B4:06:05 5 173 2
unknown parameter: CB:51:62:B4:06:05
uart_cli:~$ gatt notification  on CB:51:62:B4:06:05
Wrong characteristic UUID or the CCCD descriptor has not been found yet
uart_cli:~$ gatt notification  on CB:51:62:B4:06:05 5
Type of write operation: 0x1
Data was written to the server 
uart_cli:~$ gatt write  request CB:51:62:B4:06:05 5 173 2
Type of write operation: 0x1
Data was written to the server 
Notification data: 1 72   //电量数据
uart_cli:~$ gatt characteristics CB:51:62:B4:06:05 1 
Characteristic UUID: 3
Parameters:
broadcast: 0 read: 0 write_wo_resp: 0 write: 0 notify: 1
indicate: 0 auth_signed_wr: 0
<info> app: search start :1 ,end:7
<info> app: search start :8 ,end:8
<info> app: search start :9 ,end:14
<info> app: handle_range start :12 ,end:14
<info> app: on_characteristics_discovery_rsp count:1, offset:1 value_handle:11

Characteristic UUID: 2
Parameters:
broadcast: 0 read: 0 write_wo_resp: 1 write: 1 notify: 0
indicate: 0 auth_signed_wr: 0
<info> app: search start :1 ,end:7
<info> app: search start :8 ,end:8
<info> app: search start :9 ,end:14
<info> app: search start :15 ,end:65535
<info> app: handle_range start :15 ,end:0
<info> app: on_characteristics_discovery_rsp count:1, offset:2 value_handle:14

Number of characteristics: 2

//方块id,链接面
uart_cli:~$ gatt notification  on CB:51:62:B4:06:05 3
Type of write operation: 0x1
Data was written to the server 
Notification data: 0 0 0 3 80 0 100 
Notification data: 0 0 0 3 80 0 100 
Notification data: 80 0 100 2 80 0 66 
Notification data: 80 0 100 2 80 0 66 
Notification data: 80 0 100 5 128 1 209 
Notification data: 80 0 100 5 128 1 209 
Notification data: 80 0 100 5 0 0 0 
Notification data: 80 0 100 5 128 1 209 
Notification data: 80 0 100 5 128 1 209 
Notification data: 128 1 209 2 80 0 126 
Notification data: 128 1 209 2 80 0 126 
uart_cli:~$