EFR32使用zigbee Scene功能

在Zigbee协议中,有Scene这个cluster,用来解决“场景”这个概念,比如在智能家居里面有读书模式、娱乐模式,等不同灯光效果,我们通过对不同的场景设定不同的状态,包括亮度、颜色、饱和度等。

Scene这个功能要依赖于Group,通常会对一组设备里的个体设置不同颜色。有文章说Scene场景功能可以不依赖于Group,这样不能通过组播来完成,只能广播发数据,增加了网络负担,实现效果不是最优。

说回来我们为什么要用场景呢?其实不用也可以,还可以通过发多条命令向控制设备,达到效果。设想,假如对一个灯泡发三条命令,6个灯泡就要发18条命令,无疑增加了网络负担,而且操作很“笨拙”。

基于此,我们需要先建立一个group,然后再对这个group里的设备添加场景。EFR32芯片使用的SDK已经集成了命令进来,演示实际操作命令。

场景用到的命令函数

zcl scenes add 
	<uint16_t> group id
	<uint8_t> scene id
	<uint16_t> transition time
	<string> scene name
	<uint32_t> extension field sets
	
zcl scenes recall
	<uint16_t> group_id
	<uint8_t> scene_id
	<uint16_t> transition time
	
send (args)
	<uint16_t> short id of the device to send the message to
	<uint8_t>  the endpoint to send the message from
	<uint8_t> the endpoint to send the message to
	
send_multicast (args)
	<uint16_t> group id of the multicast group to send the message to
	<uint8_t> the endpoint to send the message from
		

组建立
添加2个灯泡进来

zcl group add 0x1234 "light"
send 0x1E08 1 11

zcl group add 0x1234 "light"
send 0x106E 1 11

EFR32使用zigbee Scene功能_第1张图片
EFR32使用zigbee Scene功能_第2张图片
可以测试一下组控制是否OK

zcl on-off toggle
send_multicast 0x1234 1 

可以观察到灯有明暗变化,证明group控制成功

场景建立

zcl scenes add  0x1234 0x1 1 "light scene" 0x01010006
send 0x1E80 1 11

zcl scenes add 0x1234 0x1 1 "light scene" 0x01010006
send 0x106E 1 11

EFR32使用zigbee Scene功能_第3张图片
EFR32使用zigbee Scene功能_第4张图片

场景执行

zcl scenes recall 0x1234 0x1 1
send_multicast 0x1234 1

EFR32使用zigbee Scene功能_第5张图片
可以观察到,如果我在场景调用前把灯泡关掉,通过上面的“场景执行”,看到俩个灯在1s后同时亮了起来。

如果想让灯的模式更丰富,比如颜色变为红色,绿色,就要在添加场景时,对不同的cluster进行设置,设置extension field sets

目前测试只支持开、关,以及亮度值调整,已和原厂确认!以后可能会更新,或者自己想办法去实现,支持更多extension filed sets

你可能感兴趣的:(SiliconLabs,Zigbee,zigbee)