使用Nordic NRF5340+NRF7002开发板尝试matter例程
[复制链接]
前期准备
根据nordic官方文档搭建好开发环境.地址:https://nrfconnect.github.io/vscode-nrf-connect/get_started/install.html
下载配置工具chip-tool,地址:
创建例程
看图,通过例子创建工程,分别创建Matter Light Bulb和Matter Light Switch.
编译两个工程,如果没有编译配置,可以通过add build configuration来添加,这个主要是选择相应的板子:
配置好两个工程之后可以通过Build All Configurations来编译所有工程,或者通过对应工程的编译按钮进行分别编译.
分别下载例程到开发板,过程如下图,按序号进行:
配置
配网使用如下命令,我使用的是直接连接路由器,即matter over wifi:
参考链接:https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.4/matter/chip_tool_guide.html
./chip-tool-debug pairing ble-wifi <node id> <ssid> <passwd> <pin_code> <discriminator>
node id是自定义的,用于后面节点的绑定,在fabric(网络)中唯一
ssid是wifi名,passwd是wifi密码,这部分也支持hex形式,我直接用的明文
pin_code和discriminator可以查看串口日志,内容大概如下:
I: 428 [DL] Product Name: not-specified
I: 432 [DL] Hardware Version: 0
I: 435 [DL] Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
I: 440 [DL] Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3840 (0xF00)
I: 446 [DL] Manufacturing Date: 2022-01-01
I: 450 [DL] Device Type: 65535 (0xFFFF)
日志中可以看到Pin Code和Discriminator分别是20202021和3840
配网命令举例:
./chip-tool-debug pairing ble-wifi 0x1233 CU_3cm6 123456ab 20202021 3840
./chip-tool-debug pairing ble-wifi 0x1234 CU_3cm6 123456ab 20202021 3840
这个过程需要按一下板子上的按键B1来开启蓝牙功能,因为配网是借助蓝牙的.
命令运行2次,除了node id不一样,其他都一样,0x1233(4659)是Matter Light Switch,0x1234(4660)是灯Matter Light Bulb
然后是绑定bulb和switch,使用的命令如下:
chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [<light_switch_node_ID>], "targets": [{"cluster": 6, "endpoint": 1, "deviceType": null}, {"cluster": 8, "endpoint": 1, "deviceType": null}]}]' <light_bulb_node_ID> 0
替换node id之后如下:
./chip-tool-debug accesscontrol write acl '[{"fabricIndex":1,"privilege":5,"authMode":2,"subjects":[112233],"targets":null},{"fabricIndex":1,"privilege":3,"authMode": 2,"subjects":[4659],"targets":[{"cluster":6,"endpoint":1,"deviceType":null},{"cluster":8,"endpoint":1,"deviceType":null}]}]' 0x0000000000001234 0
绑定完成之后应该就可以通过switch来控制bulb了.
测试
按下switch上的B2按钮日志如下:
I: Button has been pressed, keep in this state for at least 500 ms to change light sensitivity of bound lighting devices.
I: Notify Bounded Cluster | endpoint: 1 cluster: 6
I: 4579967 [DIS]Found an existing secure session to [1:0000000000001234]!
D: 4579974 [DIS]OperationalSessionSetup[1:0000000000001234]: State change 1 --> 5
I: 4579982 [EM]<<< [E:44316i S:40176 M:82341530] (S) Msg TX to 1:0000000000001234 [76BE] [UDP:[fe80::16c1:ffff:fe00:fc5f]:5540] --- Type 0001:08 (IM:InvokeCommandRequest)
I: 4580099 [EM]>>> [E:44316i S:40176 M:266680066 (Ack:82341530)] (S) Msg RX from 1:0000000000001234 [76BE] --- Type 0001:09 (IM:InvokeCommandResponse)
I: 4580112 [DMG]Received Command Response Status for Endpoint=1 Cluster=0x0000_0006 Command=0x0000_0002 Status=0x0
D: Binding command applied successfully!
I: 4580127 [EM]<<< [E:44316i S:40176 M:82341531 (Ack:266680066)] (S) Msg TX to 1:0000000000001234 [76BE] [UDP:[fe80::16c1:ffff:fe00:fc5f]:5540] --- Type 0000:10 (SecureChannel:StandaloneAck)
对应的bulb日志如下:
I: 4645373 [EM]>>> [E:44316r S:46234 M:82341530] (S) Msg RX from 1:0000000000001233 [76BE] --- Type 0001:08 (IM:InvokeCommandRequest)
I: 4645385 [ZCL]Toggle ep1 on/off from state 0 to 1
I: 4645390 [ZCL]On Command - OffWaitTime : 0
I: 4645394 [ZCL]On/Toggle Command - Stop Timer
I: 4645399 [ZCL]Cluster OnOff: attribute OnOff set to 1
I: Turn On Action has been initiated
I: Turn On Action has been completed
I: 4645410 [ZCL]Cluster LevelControl: attribute CurrentLevel set to 1
I: 4645418 [EM]<<< [E:44316r S:46234 M:266680066 (Ack:82341530)] (S) Msg TX to 1:0000000000001233 [76BE] [UDP:[fe80::16c1:ffff:fe00:d84d]:5540] --- Type 0001:09 (IM:InvokeCommandResponse)
I: 4645436 [ZCL]Cluster LevelControl: attribute CurrentLevel set to 254
I: Level Action has been initiated
I: Setting brightness level to 254
I: Level Action has been completed
I: 4645495 [EM]>>> [E:44316r S:46234 M:82341531 (Ack:266680066)] (S) Msg RX from 1:0000000000001233 [76BE] --- Type 0000:10 (SecureChannel:StandaloneAck)
此时bulb上的led就会改变状态,如果是亮的状态就会熄灭,如果是熄灭状态就会点亮.
如果重启板子,会自动联网配对,无需再配置.
到此测试完成.
|