Matter: chip-tool的使用
chip-tool运行方式
可以通过单次执行和交互执行,单次执行某条指令需要在规则时间内完成,否者chip-tool将会报错:Timeout;交互执行某条命令时,相应速度很快,也不容易出现超时错误,建议使用交互执行。
进入交互执行的命令:
./chip-tool interactive start
配网
例如:使用 ble 对 matter over wifi 设备进行配网
./chip-tool interactive start
pairing ble-wifi 0x7283 <ssid> <passphrase> 20202021 3840
- 0x7283: 手动设置的node_id
- ssid: WiFi名称
- passphrase: WiFi密码
- 20202021: Passcode,ESP测试设备默认使用20202021
- 3840: Discriminator,ESP测试设备默认使用3840
例如:使用 ble 对 matter over wifi 设备进行配网
./chip-tool interactive start
# pairing ble-thread 0x7283 hex:<DATASET> <setup-pin-code> <discriminator> --bypass-attestation-verifier true --ble-adapter 1
./chip-tool pairing ble-thread 0x1005 hex:0e0800000000000100004a0300001835060004001fffe00708fd1de4307d4beaf2030f4f70656e5468726561642d636438640410971c66b44e57a41db87782c05339a6830c0402a0f7f8051000112233445566778899aabbccddeeff0208111111112222222201021234000300000f 44916308 3277 --ble-adapter 1 --bypass-attestation-verifier true
- 0x7283: 手动设置的node_id
- DATASET: Thread网络配置的DATASET
- setup-pin-code: Passcode
- discriminator: Discriminator
- --bypass-attestation-verifier true: 跳过认证
- --ble-adapter 1: 本地有蓝牙适配器0、1,现在指定使用蓝牙适配器1
例如:通过MT码添加 Matter over Thread设备
./chip-tool pairing code-thread 0x1005 hex:0e0800000000000100004a0300001835060004001fffe00708fd1de4307d4beaf2030f4f70656e5468726561642d636438640410971c66b44e57a41db87782c05339a6830c0402a0f7f8051000112233445566778899aabbccddeeff0208111111112222222201021234000300000f MT:CWBT0A-E15BHCZ52-00 --ble-adapter 1 --bypass-attestation-verifier true
- 0x1005: 用户自定义的node_id
- MT:CWBT0A-E15BHCZ52-00: 扫描Matter设备上的码出来的信息
例如:一个 matter bridge 设备已经添加到 Apple Home,此时将该设备添加到chip-tool
./chip-tool interactive start
pairing code 0x1 12207156541 --bypass-attestation-verifier true
其中:
0x1: 手动分配的node_id
12207156541:11位配对码
--bypass-attestation-verifier true:表示跳过认证过程,一般通过认证的Matter设备都带有认证信息,添加设备时会通过云端数据进行比对。此时,仅使用chip-tool进行测试,所以跳过认证。
例如:将设备移除Matter网络
./chip-tool pairing unpair <node_id>
- <node_id>: Matter设备的node id
查询
例如:读取Descriptor cluster下的Attribute
descriptor read server-list 0x1 0x3
其中:
descriptor:代表cluster_name
read:
server-list:代表attribute_name
0x1:代表node_id
0x3:代表endpoint_id
例如:对一个matter-bridge设备读取 parts-list
>>> descriptor read parts-list 0x1 0x1
[1745399034.955] [254735:254735] [TOO] Command: descriptor read parts-list 0x1 0x1
[1745399034.955] [254735:254737] [TOO] Sending command to node 0x1
[1745399034.956] [254735:254737] [CSM] FindOrEstablishSession: PeerId = [1:0000000000000001]
[1745399034.956] [254735:254737] [CSM] FindOrEstablishSession: No existing OperationalSessionSetup instance found
[1745399034.956] [254735:254737] [DIS] Found an existing secure session to [1:0000000000000001]!
[1745399034.956] [254735:254737] [DIS] OperationalSessionSetup[1:0000000000000001]: State change 1 --> 5
[1745399034.956] [254735:254737] [TOO] Sending ReadAttribute to:
[1745399034.956] [254735:254737] [TOO] cluster 0x0000_001D, attribute: 0x0000_0003, endpoint 1
[1745399034.956] [254735:254737] [DMG] SendReadRequest ReadClient[0x7a8c5c038c50]: Sending Read Request
[1745399034.956] [254735:254737] [DMG] 0 data version filters provided, 0 not relevant, 0 encoded, 0 skipped due to lack of space
[1745399034.956] [254735:254737] [EM] <<< [E:48696i S:49655 M:178050833] (S) Msg TX from 000000000001B669 to 1:0000000000000001 [7322] [UDP:[fe80::b91c:e18b:d2aa:62ff%enx68da73af2746]:5540] --- Type 0001:02 (IM:ReadRequest) (B:51)
[1745399034.956] [254735:254737] [EM] ??1 [E:48696i S:49655 M:178050833] (S) Msg Retransmission to 1:0000000000000001 in 587ms [State:Idle II:500 AI:300 AT:4000]
[1745399034.956] [254735:254737] [DMG] MoveToState ReadClient[0x7a8c5c038c50]: Moving to [AwaitingIn]
[1745399034.966] [254735:254737] [EM] >>> [E:48696i S:49655 M:211981841 (Ack:178050833)] (S) Msg RX from 1:0000000000000001 [7322] to 000000000001B669 --- Type 0001:05 (IM:ReportData) (B:80)
[1745399034.966] [254735:254737] [EM] Found matching exchange: 48696i, Delegate: 0x7a8c5c038c60
[1745399034.966] [254735:254737] [EM] Rxd Ack; Removing MessageCounter:178050833 from Retrans Table on exchange 48696i
[1745399034.966] [254735:254737] [DMG] ReportDataMessage =
[1745399034.966] [254735:254737] [DMG] {
[1745399034.966] [254735:254737] [DMG] AttributeReportIBs =
[1745399034.966] [254735:254737] [DMG] [
[1745399034.966] [254735:254737] [DMG] AttributeReportIB =
[1745399034.966] [254735:254737] [DMG] {
[1745399034.966] [254735:254737] [DMG] AttributeDataIB =
[1745399034.966] [254735:254737] [DMG] {
[1745399034.966] [254735:254737] [DMG] DataVersion = 0x2d105b8,
[1745399034.966] [254735:254737] [DMG] AttributePathIB =
[1745399034.966] [254735:254737] [DMG] {
[1745399034.966] [254735:254737] [DMG] Endpoint = 0x1,
[1745399034.966] [254735:254737] [DMG] Cluster = 0x1d,
[1745399034.966] [254735:254737] [DMG] Attribute = 0x0000_0003,
[1745399034.966] [254735:254737] [DMG] }
[1745399034.966] [254735:254737] [DMG]
[1745399034.966] [254735:254737] [DMG] Data = [
[1745399034.966] [254735:254737] [DMG] 3 (unsigned), 4 (unsigned), 5 (unsigned), 6 (unsigned), 7 (unsigned),
[1745399034.966] [254735:254737] [DMG] ],
[1745399034.966] [254735:254737] [DMG] },
[1745399034.966] [254735:254737] [DMG]
[1745399034.966] [254735:254737] [DMG] },
[1745399034.966] [254735:254737] [DMG]
[1745399034.966] [254735:254737] [DMG] ],
[1745399034.966] [254735:254737] [DMG]
[1745399034.966] [254735:254737] [DMG] SuppressResponse = true,
[1745399034.966] [254735:254737] [DMG] InteractionModelRevision = 11
[1745399034.966] [254735:254737] [DMG] }
[1745399034.966] [254735:254737] [TOO] Endpoint: 1 Cluster: 0x0000_001D Attribute 0x0000_0003 DataVersion: 47252920
[1745399034.966] [254735:254737] [TOO] PartsList: 5 entries
[1745399034.966] [254735:254737] [TOO] [1]: 3
[1745399034.966] [254735:254737] [TOO] [2]: 4
[1745399034.966] [254735:254737] [TOO] [3]: 5
[1745399034.966] [254735:254737] [TOO] [4]: 6
[1745399034.966] [254735:254737] [TOO] [5]: 7
[1745399034.966] [254735:254737] [EM] <<< [E:48696i S:49655 M:178050834 (Ack:211981841)] (S) Msg TX from 000000000001B669 to 1:0000000000000001 [7322] [UDP:[fe80::b91c:e18b:d2aa:62ff%enx68da73af2746]:5540] --- Type 0000:10 (SecureChannel:StandaloneAck) (B:34)
[1745399034.966] [254735:254737] [EM] Flushed pending ack for MessageCounter:211981841 on exchange 48696i
订阅
对OnOff attribute 进行订阅:
./chip-tool interactive start
onoff subscribe on-off 0 60 0x1 0x4
0: min-interval
60: max-interval
0x1: node_id
0x4: endpoint_id
解析
将QR码(扫描设备即可获取)解析出来: discriminator、passcode
>>> payload parse-setup-payload MT:Y.K9042C00KA0648G00
[1745391190.063] [254735:254735] [TOO] Command: payload parse-setup-payload MT:Y.K9042C00KA0648G00
[1745391190.063] [254735:254735] [SPL] Parsing base38Representation: MT:Y.K9042C00KA0648G00
[1745391190.063] [254735:254735] [SPL] Version: 0
[1745391190.063] [254735:254735] [SPL] VendorID: 65521
[1745391190.063] [254735:254735] [SPL] ProductID: 32768
[1745391190.063] [254735:254735] [SPL] Custom flow: 0 (STANDARD)
[1745391190.063] [254735:254735] [SPL] Discovery Bitmask: 0x02 (BLE)
[1745391190.063] [254735:254735] [SPL] Long discriminator: 3840 (0xf00)
[1745391190.063] [254735:254735] [SPL] Passcode: 20202021
>>>
解析出来的信息:
- discriminator 对应 Long discriminator:3840 (0xf00)
- passcode 对应 Passcode:20202021
创建手动配对码
已经知道了passcode 和 descriminator,如何创建手动配对码?
alex@alex-NMH-WCX9:~/workspace/connectedhomeip/out/host$ ./chip-tool payload generate-manualcode --discriminator 3840 --setup-pin-code 20202021
[1747054313.118895][85857:85857] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_tool_kvs
[1747054313.118944][85857:85857] CHIP:TOO: Manual Code: 34970112332
11位配对码:34970112332
修改持久化存储目录
创建目录 mkdir -p ~/.chip-tool
在 ~/.bashrc 中添加 export TMPDIR=~/.chip-tool,激活 source ~/.bashrc。
群组控制
- 首先在设备ACL中使能指定Group ID的访问
chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null},{"fabricIndex": 1, "privilege": 4, "authMode": 3, "subjects": [1], "targets": null}]' 0x1002 0
- "fabricIndex": 1 表示第一个fabric网络
- "subjects": [1]: 这里的1表示 group_id
- 0x1002 0: 0x1002表示node_id, 0表示endpoint_id
- 向设备写入
Epoch Key用于加密
chip-tool groupkeymanagement key-set-write '{"groupKeySetID": 1,"groupKeySecurityPolicy": 0, "epochKey0":"d0d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime0": 1,"epochKey1":"d1d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime1": 18446744073709551613,"epochKey2":"d2d1d2d3d4d5d6d7d8d9dadbdcdddedf", "epochStartTime2": 18446744073709551614 }' 0x1002 0
- 0x1002 0: 0x1002表示node_id, 0表示endpoint_id
- 将
密钥ID和GroupID绑定
chip-tool groupkeymanagement write group-key-map '[{"groupId": 1, "groupKeySetID": 1, "fabricIndex": 1}]' 0x1002 0
- 0x1002 0: 0x1002表示node_id, 0表示endpoint_id
- 将结点添加到指定 GroupID
chip-tool groups add-group 0x0001 group_light 0x1002 1
- group_light: 自定义的group名称
- 0x1002 1:0x1002表示node_id, 1表示endpoint_id
- 查看是否添加成功
chip-tool groupkeymanagement read group-table 0x1002 0
- 0x1002 0: 0x1002表示node_id, 0表示endpoint_id
注意:步骤1至步骤5仅表示将一个设备添加到一个group中。如果有多个设备,则需要重复执行步骤1至步骤5
- 将 controller 加入到群组中
chip-tool groupsettings add-group group_light 0x001
- group_light: 自定义的group名称
- 0x001: group id
- 添加 controller 组秘钥
chip-tool groupsettings add-keysets 0x0001 0 0x000000000021dfe0 hex:d0d1d2d3d4d5d6d7d8d9dadbdcdddedf
0x0001 0: 0x0001是group id, 0是???
- 绑定controller KeySet和GroupID的映射关系
chip-tool groupsettings bind-keyset 0x001 0x0001
0x0001:表示group id
注意:步骤6至步骤8表示将controller添加到group
- controller 发送控制命令给组地址
chip-tool onoff toggle 0xffffffffffff0001 1
0xffffffffffff0001: ???
1: attribute id

浙公网安备 33010602011771号