主要内容

ZigBee家庭自动化帧生成和解码

这个例子展示了如何为家庭自动化应用程序配置文件生成和解码应用程序层框架[1]的ZigBee®规范[2使用ZigBee和UWB的通信工具箱™库。

背景

ZigBee标准[2]表示低速率无线个人区域网络的网络层(NET或NWK)和应用层(APP或APL)。这些NET和app层规范基于IEEE®802.15.4™的PHY和MAC规范[3.].ZigBee设备应用于家庭自动化和传感器网络,与物联网(IoT)趋势高度相关。

ZigBee应用层由多个子层组成:(我)应用程序支持子层(APS)金宝app(2)ZigBee集群库(ZCL)。APS子层遵循所有应用程序概要文件和ZigBee集群的通用格式(参见[2])。的ZCL采用所有组别通用的格式(见[4])。的ZCL有效载荷仅由某些集群使用,并且遵循特定于集群的格式。

集群和帧捕获

在家庭自动化应用程序配置文件中使用的所有集群中,这个示例解码并生成帧:(我)On/Off集群(用于照明设备),以及(2)入侵者报警系统(IAS)区域集群(由运动传感器使用)[4].On/Off集群不使用ZCL有效负载,但IAS Zone集群使用。

这些集群的帧已从商用ZigBee无线电捕获,实现家庭自动化,使用USRP®B200-mini无线电和USRP®无线电通信工具箱支持包金宝app.ZigBee既可以在网络层也可以在应用层采用安全性。捕获的帧在网络层采用了安全性,随后被解密。此示例解码已解密的net层有效负载的应用层。

负载zigbeeAPPCaptures

家庭自动化ZigBee无线电的APS帧解码

一个无线个域网。一个PSFrameConfig配置对象用于生成和解码ZigBee APS帧。这些对象描述了一个aps层框架,并指定了它的框架类型和所有适用的属性。的无线个域网。一个PSFrameDecoder函数接受以字节为单位的APS协议数据单元(APDU)并输出zigbee。APSFrameConfig对象,以字节为单位描述帧和可能的ZCL帧。第2.2.5.1条2APS帧格式。

接下来,被捕获的IAS Zone帧的APS子层被解码:

[apsConfig, apsPayload] = zigbee.APSFrameDecoder(motionDetectedFrame);apsConfig
apsConfig = APSFrameConfig with properties: FrameType: 'Data' APSCounter: 230 acknowledgement request: 1 Addressing: DeliveryMode: 'Unicast' DestinationEndpoint: '01' ClusterID: '0500' ProfileID: '0104' SourceEndpoint: '01'扩展头:ExtendedHeader: 0安全:安全:0

家庭自动化ZigBee无线电ZCL报头解码

一个无线个域网。ZCLFrameConfig配置对象用于生成和解码ZigBee ZCL报头。这些对象描述了一个zcl层框架,并指定了它的框架类型和所有适用的属性。

无线个域网。ZCLFrameDecoder函数接受以字节为单位的ZCL帧并输出zigbee。ZCLFrameConfigobject describing the header and possibly a ZCL payload in bytes. Clause 2.4.1 in [4描述了ZCL报头帧格式。请注意,ZCL头可以指定“库范围”或“特定于集群”的命令类型。在后一种情况下,zigbee。ZCLFrameDecoderalso needs the cluster ID, which is present in the APS header, in order to decode the cluster-specific command ID into a command type. For example, the next command decodes the ZCL header of a captured IAS Zone frame.

[zclConfig, zclPayload] = zigbee.使用实例ZCLFrameDecoder(apsPayload, apsConfig.ClusterID); zclConfig
zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Zone Status Change Notification' SequenceNumber: 9 ManufacturerCommand: 0 Direction: 'Downlink' DisableDefaultResponse: 0

ZigBee无线电对IAS区域帧ZCL有效载荷的解码

与On/Off集群相比,IAS Zone集群除ZCL报头外还指定了ZCL有效负载。一个无线个域网。IASZoneFrameConfig配置对象用于生成和解码IAS Zone ZCL有效载荷。这些对象描述了IAS Zone有效负载和所有适用的属性。的无线个域网。IASZoneFrameDecoder函数接受以字节为单位的IAS Zone有效负载并输出zigbee。描述IAZ Zone有效负载的IASZoneFrameConfig对象。

iasZoneConfig = zigbee.IASZoneFrameDecoder(zclPayload)
iasZoneConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alarming ' Alarm2: ' alarming ' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0

ZigBee无线电运动触发照明自动化解码

建立了商用家用ZigBee无线电的照明自动化系统,并对其帧进行了捕获和解码。具体来说,一旦运动传感器检测到运动,它就会向ZigBee集线器发送信号,而ZigBee集线器又会向灯泡发送信号,从而使灯泡亮起。当运动传感器检测到运动已经停止时(例如,10秒后没有运动),它会向ZigBee集线器发送信号,后者会通过无线方式触发灯泡熄灭。下面的视频演示了照明自动化。

helperPlaybackVideo (“LightingAutomation.mp4”, 2/5);

下面的代码解码在ZigBee无线电之间传输的实际帧。这些都是用USRP®设备捕获的(也在视频中显示)。

apsFrames = {motionDetectedFrame;turnOnFrame;motionStoppedFrame;turnOffFrame};idx = 1:length(apsFrames)% APS解码:[apsConfig, apsPayload] = zigbee.APSFrameDecoder(apsFrames{idx});% ZCL报头解码:[zclConfig, zclPayload] = zigbee.使用实例ZCLFrameDecoder(apsPayload, apsConfig.ClusterID); zclConfig开-关集群(没有ZCL有效负载)onOffClusterID =“0006”如果比较字符串(apsConfig。ClusterID, onOffClusterID)“转灯泡”低(zclConfig.CommandType)”。\ n”]);结束%入侵者报警系统(IAS)区域集群具有ZCL有效载荷:iasZoneClusterID =“0500”如果~isempty(zclPayload) && strcmp(apsConfig. conf)ClusterID, iasZoneClusterID) iasConfig = zigbee.IASZoneFrameDecoder(zclPayload)如果任何(strcmp (“警告”, {iasConfig。一个larm1, iasConfig.Alarm2})) fprintf(“运动检测。\ n”);其他的流(“运动停止。\ n”);结束结束结束
zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Zone Status Change Notification' SequenceNumber: 9 ManufacturerCommand: 0 Direction: 'Downlink' DisableDefaultResponse: 0 iasConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alarming ' Alarm2: ' alarming ' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0 Motion detected。zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'On' SequenceNumber: 64 ManufacturerCommand: 0 Direction: 'Uplink' DisableDefaultResponse: 0打开灯泡。zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Zone Status Change Notification' SequenceNumber: 10 ManufacturerCommand: 0 Direction: 'Downlink' DisableDefaultResponse: 0 iasConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alarm ' Alarm2: 'Not alarm ' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0运动停止。zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Off' SequenceNumber: 70 ManufacturerCommand: 0 Direction: 'Uplink' DisableDefaultResponse: 0关闭灯泡。

生成IAS区域ZCL有效载荷

无线个域网。IASZoneFrameGenerator函数接受zigbee。IASZoneFrameConfigobject describing the IAS Zone payload and outputs the payload in bytes. The following code creates two ZCL payloads for this cluster indicating that intrusion has or has not been detected.

iasConfigIntrusion = zigbee。IASZoneFrameConfig (“Alarm2”“警告”);zclPayloadIntrusion = zigbee.IASZoneFrameGenerator(iasConfigIntrusion);iasConfigNoIntrusion = zigbee。IASZoneFrameConfig (“Alarm2”“不担心”);zclPayloadNoIntrusion = zigbee.IASZoneFrameGenerator(iasConfigNoIntrusion);

生成ZCL帧

无线个域网。ZCLFrameGenerator函数接受zigbee。ZCLFrameConfigobject describing the frame, and optionally a ZCL payload in bytes (two-characters), and outputs the ZCL frame in bytes. The following code generates ZCL frames for the On/Off cluster (no payload) and the IAS Zone cluster (payload needed).

% IAS区域集群zclConfigIntrusion = zigbee。ZCLFrameConfig (“FrameType”提供集群范围内的...“CommandType”“分区状态更改通知”...“SequenceNumber”, 1“方向”“下行”);zclFrameIntrusion = zigbee。ZCLFrameGenerator(zclConfigIntrusion, zclPayloadIntrusion);%开启/关闭集群zclConfigOn = zigbee。ZCLFrameConfig (“FrameType”提供集群范围内的...“CommandType”“上”...“SequenceNumber”2,“方向”“上行”);zclFrameOn = zigbee.ZCLFrameGenerator(zclConfigOn);

生成APS帧

无线个域网。一个PSFrameGenerator函数接受zigbee。APSFrameConfigobject describing the frame, and optionally a APS payload (ZCL-layer frame) in bytes (two-characters), and outputs the APS frame in bytes. The following code illustrates how to generate APS frames for the ZCL frames created in the previous section.

% IAS区域集群apsConfigIntrusion = zigbee。APSFrameConfig (“FrameType”“数据”...“ClusterID”iasZoneClusterID,...“ProfileID”zigbee.profileID (“家庭自动化”),...“APSCounter”, 1...“AcknowledgmentRequest”,真正的);apsFrameIntrusion = zigbee。APSFrameGenerator(apsConfigIntrusion, zclFrameIntrusion);%开启/关闭集群apsConfigOn = zigbee。APSFrameConfig (“FrameType”“数据”...“ClusterID”onOffClusterID,...“ProfileID”zigbee.profileID (“家庭自动化”),...“APSCounter”2,...“AcknowledgmentRequest”,真正的);apsFrameOn = zigbee。APSFrameGenerator(apsConfigOn, zclFrameOn);

进一步的探索

您可以进一步探索以下生成器和解码函数,以及配置对象:

选定的参考书目

  1. ZigBee联盟,ZigBee家庭自动化公共应用概要,修订29,v. 1.2, 2013年6月。

  2. ZigBee联盟,ZigBee规范文档053474r17, 2007

  3. IEEE 802.15.4-2011局域网和城域网IEEE标准第15.4部分:低速率无线个人区域网络(lr - wpan)

  4. ZigBee联盟,ZigBee集群库规范,修订版6,2016年1月。