-
使用ROOT
-
-
#hcitool lescan ### 扫描低功耗蓝牙设备
-
C3:E7:A5:6A:D6:43 T207A
-
-
#gatttool -b C3:E7:A5:6A:D6:43 -I ### 打开一个与远程设备的会话,-I 表示交互模式
-
[C3:E7:A5:6A:D6:43][LE]> help
-
-
help Show this help
-
exit Exit interactive mode
-
quit Exit interactive mode
-
connect [address [address type]] Connect to a remote device
-
disconnect Disconnect from a remote device
-
primary [UUID] Primary Service Discovery
-
included [start hnd [end hnd]] Find Included Services
-
characteristics [start hnd [end hnd [UUID]]] Characteristics Discovery
-
char-desc [start hnd] [end hnd] Characteristics Descriptor Discovery
-
char-read-hnd <handle> Characteristics Value/Descriptor Read by handle
-
char-read-uuid <UUID> [start hnd] [end hnd] Characteristics Value/Descriptor Read by UUID
-
char-write-req <handle> <new value> Characteristic Value Write (Write Request)
-
char-write-cmd <handle> <new value> Characteristic Value Write (No response)
-
sec-level [low | medium | high] Set security level. Default: low
-
mtu <value> Exchange MTU for GATT/ATT
-
### connect 表示连接远程设备,连接成功后,提示符签名的状态会显示 "CON" :
-
[C3:E7:A5:6A:D6:43][LE]> connect
-
Attempting to connect to C3:E7:A5:6A:D6:43
-
Connection successful
-
[C3:E7:A5:6A:D6:43][LE]> ### 此时 前缀颜色会变成蓝色, 代表连接成功。
-
-
### primary 命令会列出远程设备上所有的 Service ,每个服务所在的 handle 范围
-
[C3:E7:A5:6A:D6:43][LE]> primary
-
attr handle: 0x0001, end grp handle: 0x0009 uuid: 00001800-0000-1000-8000-00805f9b34fb
-
attr handle: 0x000a, end grp handle: 0x000a uuid: 00001801-0000-1000-8000-00805f9b34fb
-
attr handle: 0x000b, end grp handle: 0xffff uuid: 680c21d9-c946-4c1f-9c11-baa1c21329e7
-
-
### 用 primary 680c21d9-c946-4c1f-9c11-baa1c21329e7 查看 UUID 的 Service
-
[C3:E7:A5:6A:D6:43][LE]> primary 680c21d9-c946-4c1f-9c11-baa1c21329e7
-
Starting handle: 0x000b Ending handle: 0xffff
-
-
### 执行 characteristics 0x000b 0xffff 可以发现它有N个 characteristics :
-
[C3:E7:A5:6A:D6:43][LE]> characteristics 0x000b 0xffff
-
handle: 0x000c, char properties: 0x1a, char value handle: 0x000d, uuid: 3f0afd88-7770-46b0-b5e7-9fc099598964
-
handle: 0x000f, char properties: 0x12, char value handle: 0x0010, uuid: 003bbdf2-c634-4b3d-ab56-7ec889b89a37
-
handle: 0x0012, char properties: 0x1a, char value handle: 0x0013, uuid: a02b947e-df97-4516-996a-1882521e0ead
-
handle: 0x0015, char properties: 0x1a, char value handle: 0x0016, uuid: f0f26c9b-2c8c-49ac-ab60-fe03def1b40c
-
handle: 0x0018, char properties: 0x1a, char value handle: 0x0019, uuid: 7bd47f30-5602-4389-b069-8305731308b6
-
handle: 0x001b, char properties: 0x1a, char value handle: 0x001c, uuid: 80f9d8bc-3bff-45bb-a181-2d6a37991208
-
handle: 0x001e, char properties: 0x12, char value handle: 0x001f, uuid: 1e63b1eb-d4ed-444e-af54-c1e965192501
-
handle: 0x0021, char properties: 0x12, char value handle: 0x0022, uuid: 17b1613e-98f2-4436-bcde-23af17a10c72
-
handle: 0x0024, char properties: 0x12, char value handle: 0x0025, uuid: 28d01d60-89de-4bfa-b6e9-651ba596232c
-
handle: 0x0027, char properties: 0x12, char value handle: 0x0028, uuid: 5b10c428-af2f-486f-aee1-9dbd79b6bccb
-
handle: 0x002a, char properties: 0x12, char value handle: 0x002b, uuid: 9eed0e27-09c0-4d1c-bd92-7c441daba850
-
handle: 0x002d, char properties: 0x18, char value handle: 0x002e, uuid: 5955aa10-e085-4030-8aa6-bdfac89ac32b
-
handle: 0x0030, char properties: 0x18, char value handle: 0x0031, uuid: ed83b848-da03-4a0a-a2dc-8b401080e473
-
handle: 0x0033, char properties: 0x12, char value handle: 0x0034, uuid: f4a67d7d-379d-4183-9c03-4b6ea5103291
-
handle: 0x0036, char properties: 0x12, char value handle: 0x0037, uuid: 0eb2bc59-baf1-4c1c-8535-8a0204c69de5
-
### char properties 表示 characteristic 的属性
-
### char value handle 表示 characteristic 的值所在的 attribute 的 handle
-
-
-
[C3:E7:A5:6A:D6:43][LE]> char-desc 0x000b 0xffff ### 列出特征值的所有 Desc
-
handle: 0x000b, uuid: 00002800-0000-1000-8000-00805f9b34fb
-
handle: 0x000c, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x000d, uuid: 3f0afd88-7770-46b0-b5e7-9fc099598964
-
handle: 0x000e, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0010, uuid: 003bbdf2-c634-4b3d-ab56-7ec889b89a37
-
handle: 0x0011, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0012, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0013, uuid: a02b947e-df97-4516-996a-1882521e0ead
-
handle: 0x0014, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0015, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0016, uuid: f0f26c9b-2c8c-49ac-ab60-fe03def1b40c
-
handle: 0x0017, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0018, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0019, uuid: 7bd47f30-5602-4389-b069-8305731308b6
-
handle: 0x001a, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x001b, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x001c, uuid: 80f9d8bc-3bff-45bb-a181-2d6a37991208
-
handle: 0x001d, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x001e, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x001f, uuid: 1e63b1eb-d4ed-444e-af54-c1e965192501
-
handle: 0x0020, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0021, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0022, uuid: 17b1613e-98f2-4436-bcde-23af17a10c72
-
handle: 0x0023, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0024, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0025, uuid: 28d01d60-89de-4bfa-b6e9-651ba596232c
-
handle: 0x0026, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0027, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0028, uuid: 5b10c428-af2f-486f-aee1-9dbd79b6bccb
-
handle: 0x0029, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x002a, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x002b, uuid: 9eed0e27-09c0-4d1c-bd92-7c441daba850
-
handle: 0x002c, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x002d, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x002e, uuid: 5955aa10-e085-4030-8aa6-bdfac89ac32b
-
handle: 0x002f, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0030, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0031, uuid: ed83b848-da03-4a0a-a2dc-8b401080e473
-
handle: 0x0032, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0033, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0034, uuid: f4a67d7d-379d-4183-9c03-4b6ea5103291
-
handle: 0x0035, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
handle: 0x0036, uuid: 00002803-0000-1000-8000-00805f9b34fb
-
handle: 0x0037, uuid: 0eb2bc59-baf1-4c1c-8535-8a0204c69de5
-
handle: 0x0038, uuid: 00002902-0000-1000-8000-00805f9b34fb
-
-
### 从中选出一个比较注意的一个获取对应 handle 描述。例如 handle: 0x0010, uuid: 003bbdf2-c634-4b3d-ab56-7ec889b89a37
-
### char-read-hnd 0x0010
-
[C3:E7:A5:6A:D6:43][LE]> char-read-hnd 0x0010
-
Characteristic value/descriptor: 02 14 f5 ff ff bb ec ff ff fc fe ff ff 5b 04 31 43 9a 0e 00 00 64 35 91 ac 19 00 00 64 93 5a ce 14 00 00 64 90 10 88 22 00 00 64
-
### 当前的值为 0, 这个 characteristic 的属性是 Notify ,所以要向 handle 0x0010 写入 0x0100 (X86 是小端),使能 Notify ,然后就会不停的收到数据
-
-
[C3:E7:A5:6A:D6:43][LE]> char-write-req 0x0010 0100
-
Notification handle = 0x001a value: 41 47 3a 20 37 30 34 38 20 37 30 39 35 20 36 30 20 2d 31 37
-
...
-
-
-
以上的步骤可以使用一个命令实现,即在非交互模式下,用 --listen 选项启动监听模式来接收通知:
-
#gatttool -b C3:E7:A5:6A:D6:43 --char-write-req --handle=0x001b --value=0100 --listen
-
如果只是读取某个handle的内容, 则
-
#gatttool -b C3:E7:A5:6A:D6:43 --char-read --handle=0x0010
-
Characteristic value/descriptor: 02 14 f5 ff ff bb ec ff ff fc fe ff ff 5b 04 31 43 9a 0e 00 00 64 35 91 ac 19 00 00 64 93 5a ce 14 00 00 64 90 10 88 22 00 00 64
#gatttool --help-all
Usage:
gatttool [OPTION...]
Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gatt Show all GATT commands
--help-params Show all Primary Services/Characteristics arguments
--help-char-read-write Show all Characteristics Value/Descriptor Read/Write arguments
GATT commands
--primary Primary Service Discovery
--characteristics Characteristics Discovery
--char-read Characteristics Value/Descriptor Read
--char-write Characteristics Value Write Without Response (Write Command)
--char-write-req Characteristics Value Write (Write Request)
--char-desc Characteristics Descriptor Discovery
--listen Listen for notifications and indications
Primary Services/Characteristics arguments
-s, --start=0x0001 Starting handle(optional)
-e, --end=0xffff Ending handle(optional)
-u, --uuid=0x1801 UUID16 or UUID128(optional)
Characteristics Value/Descriptor Read/Write arguments
-a, --handle=0x0001 Read/Write characteristic by handle(required)
-n, --value=0x0001 Write characteristic value (required for write operation)
Application Options:
-i, --adapter=hciX Specify local adapter interface
-b, --device=MAC Specify remote Bluetooth address
-t, --addr-type=[public | random] Set LE address type. Default: public
-m, --mtu=MTU Specify the MTU size
-p, --psm=PSM Specify the PSM for GATT/ATT over BR/EDR
-l, --sec-level=[low | medium | high] Set security level. Default: low
-I, --interactive Use interactive mode
阅读(6363) | 评论(1) | 转发(0) |