このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
ZigBee ホーム オートメーション フレームの生成と復号化
この例では、Communications Toolbox™ を使用して、ZigBee® 仕様 [2] のホーム オートメーション アプリケーション プロファイル [1] のアプリケーションレイヤー フレームを生成および復号化する方法を説明します。
背景
ZigBee 規格 [2] は、低速無線パーソナル エリア ネットワークのネットワーク (NET または NWK) レイヤーとアプリケーション (APP または APL) レイヤーを規定します。この NET レイヤーおよび APP レイヤーの仕様は、IEEE® 802.15.4™ [3] の PHY 仕様および MAC 仕様に基づいて作成されています。ZigBee デバイスは、ホーム オートメーションやセンサー ネットワーキングに使用例があり、Internet of Things (IoT) の流行にも密接に関連しています。
ZigBee アプリケーション層は、(i) application support sublayer (APS)、(ii) ZigBee cluster library (ZCL) という複数の下位層で構成されます。APS 下位層はすべてのアプリケーション プロファイルと ZigBee クラスターに共通の形式 ([2] の Clause 2.2.5 を参照) に従います。ZCL "ヘッダー" はすべてのクラスターに共通の形式 ([4] の Clause 2.4 を参照) に従います。ZCL "ペイロード" は、一部のクラスターのみに使用され、クラスター固有の形式に従います。
クラスターとフレームの取得
ホーム オートメーション アプリケーション プロファイルで使用されるすべてのクラスターの中から、この例では、(i) On/Off クラスター (照明器具で使用される) と (ii) 侵入者警報システム (IAS) ゾーン クラスター (モーション センサーで使用される) [4] のフレームを生成および復号化します。On/Off クラスターは ZCL ペイロードを利用しませんが、IAS ゾーン クラスターは利用します。
これらのクラスターのフレームは、USRP® B200-mini 無線機と Communications Toolbox Support Package for USRP® radio を使用して、ホーム オートメーションを有効にする市販の ZigBee 無線機から取得されます。ZigBee は、ネットワーク層とアプリケーション層のいずれかでセキュリティも採用できます。取得されたフレームは、ネットワーク層のセキュリティを採用し、後で復号化されたものです。この例では、復号化した NET 層ペイロードのアプリケーション層を復号化します。
load zigbeeAPPCaptures
ホーム オートメーション ZigBee 無線機の APS フレームの復号化
zigbee.APSFrameConfig
構成オブジェクトは、ZigBee APS フレームの生成と復号化の両方で使用されます。このようなオブジェクトは、APS 層フレームを表し、そのフレーム タイプと適用可能なすべてのプロパティを指定します。関数 zigbee.APSFrameDecoder
は、APS プロトコル データ ユニット (APDU) をバイト単位で受け入れ、フレームと場合によっては ZCL フレームを表す zigbee.APSFrameConfig
オブジェクトをバイト単位で出力します。[2] の Clause 2.2.5.1 では、APS フレーム形式について説明しています。
次に、取得した IAS ゾーン フレームの APS 下位層を復号化します。
[apsConfig,apsPayload] = zigbee.APSFrameDecoder(motionDetectedFrame); apsConfig
apsConfig = APSFrameConfig with properties: FrameType: 'Data' APSCounter: 230 AcknowledgmentRequest: 1 Addressing: DeliveryMode: 'Unicast' DestinationEndpoint: '01' ClusterID: '0500' ProfileID: '0104' SourceEndpoint: '01' Extended header: ExtendedHeader: 0 Security: Security: 0
ホーム オートメーション ZigBee 無線機の ZCL ヘッダーの復号化
zigbee.ZCLFrameConfig
構成オブジェクトは、ZigBee ZCL ヘッダーの生成と復号化の両方で使用されます。このようなオブジェクトは、ZCL 層フレームを表し、そのフレーム タイプと適用可能なすべてのプロパティを指定します。
関数 zigbee.ZCLFrameDecoder
は、ZCL フレームをバイト単位で受け入れ、ヘッダーと場合によっては ZCL ペイロードを表す zigbee.ZCLFrameConfig
オブジェクトをバイト単位で出力します。[4] の Clause 2.4.1 では、ZCL ヘッダー フレーム形式について説明しています。ZCL ヘッダーは、'ライブラリ全体' のコマンド タイプと 'クラスター固有' のコマンド タイプのどちらも指定できることに注意してください。後者の場合は、クラスター固有のコマンド ID をコマンド タイプに復号化するために、APS ヘッダーに含まれるクラスター ID も zigbee.ZCLFrameDecoder
で必要です。たとえば、次のコマンドは取得した IAS ゾーン フレームの ZCL ヘッダーを復号化します。
[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 Zone フレームの ZCL ペイロードの復号化
On/Off クラスターとは対照的に、IAS ゾーン クラスターは ZCL ヘッダーに加えて ZCL ペイロードを指定します。zigbee.IASZoneFrameConfig
構成オブジェクトは、IAS ゾーン ZCL ペイロードの生成と復号化の両方で使用されます。このようなオブジェクトは、IAS ゾーン ペイロードと適用可能なすべてのプロパティを表します。関数 zigbee.IASZoneFrameDecoder
は、IAS ゾーン ペイロードをバイト単位で受け入れ、IAS ゾーン ペイロードを表す zigbee.IASZoneFrameConfig
オブジェクトを出力します。
iasZoneConfig = zigbee.IASZoneFrameDecoder(zclPayload)
iasZoneConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alarmed' Alarm2: 'Alarmed' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0
ZigBee 無線機のモーション トリガー型のライティング オートメーションの復号化
ライティング オートメーションは、そのフレームが取得および復号化されている市販のホーム オートメーション ZigBee 無線機によって成立します。具体的には、モーション センサーがモーションを検知すると、信号を ZigBee ハブに送信します。次にハブが電球に信号を送信し、電球が点灯します。モーション センサーがモーションの停止を検知すると (モーションがなくなってから 10 秒後など)、信号を ZigBee ハブに送信します。次にハブは、電球の消灯を無線でトリガーします。次のビデオは、ライティング オートメーションを示しています。
helperPlaybackVideo('LightingAutomation.mp4',2/5);
次のコードは、ZigBee 無線機間で送信された実際のフレームを復号化します。これらのフレームは、(ビデオに表示されている) USRP® デバイスで取得されました。
apsFrames = ... {motionDetectedFrame; turnOnFrame; motionStoppedFrame; turnOffFrame}; for idx = 1:length(apsFrames) % APS decoding: [apsConfig,apsPayload] = zigbee.APSFrameDecoder(apsFrames{idx}); % ZCL header decoding: [zclConfig,zclPayload] = zigbee.ZCLFrameDecoder(apsPayload, ... apsConfig.ClusterID); zclConfig % On-off cluster (does not have ZCL payload) onOffClusterID = '0006'; if strcmp(apsConfig.ClusterID,onOffClusterID) fprintf(['Turn light bulb ' lower(zclConfig.CommandType) '.\n']); end % IAS zone cluster has ZCL payload: iasZoneClusterID = '0500'; if ~isempty(zclPayload) && strcmp(apsConfig.ClusterID,iasZoneClusterID) iasConfig = zigbee.IASZoneFrameDecoder(zclPayload) if any(strcmp('Alarmed',{iasConfig.Alarm1,iasConfig.Alarm2})) fprintf('Motion detected.\n'); else fprintf('Motion stopped.\n'); end end end
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 alarmed' Alarm2: 'Alarmed' 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 Turn light bulb on. 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 alarmed' Alarm2: 'Not alarmed' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0 Motion stopped. zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Off' SequenceNumber: 70 ManufacturerCommand: 0 Direction: 'Uplink' DisableDefaultResponse: 0 Turn light bulb off.
IAS Zone ZCL ペイロードの生成
関数 zigbee.IASZoneFrameGenerator
は、IAS ゾーン ペイロードを表す zigbee.IASZoneFrameConfig
オブジェクトを受け入れ、ペイロードをバイト単位で出力します。次のコードは、このクラスターの 2 つの ZCL ペイロード (侵入検出を示すものと、侵入未検出を示すもの) を作成します。
iasConfigIntrusion = zigbee.IASZoneFrameConfig('Alarm2','Alarmed'); zclPayloadIntrusion = zigbee.IASZoneFrameGenerator(iasConfigIntrusion); iasConfigNoIntrusion = zigbee.IASZoneFrameConfig('Alarm2','Not alarmed'); zclPayloadNoIntrusion = zigbee.IASZoneFrameGenerator(iasConfigNoIntrusion);
ZCL フレームの生成
関数 zigbee.ZCLFrameGenerator
は、フレームを表す zigbee.ZCLFrameConfig
オブジェクトと、オプションで ZCL ペイロードをバイト単位 (2 文字) で受け入れ、ZCL フレームをバイト単位で出力します。次のコードは、On/Off クラスターの ZCL フレーム (ペイロードなし) と IAS ゾーン クラスターの ZCL フレーム (ペイロードが必要) を生成します。
% IAS Zone Cluster zclConfigIntrusion = zigbee.ZCLFrameConfig( ... 'FrameType','Cluster-specific', ... 'CommandType','Zone Status Change Notification', ... 'SequenceNumber',1,'Direction','Downlink'); zclFrameIntrusion = zigbee.ZCLFrameGenerator(zclConfigIntrusion, ... zclPayloadIntrusion); % On/Off Cluster zclConfigOn = zigbee.ZCLFrameConfig( ... 'FrameType','Cluster-specific', ... 'CommandType','On', ... 'SequenceNumber',2,'Direction','Uplink'); zclFrameOn = zigbee.ZCLFrameGenerator(zclConfigOn);
APS フレームの生成
関数 zigbee.APSFrameGenerator
は、フレームを表す zigbee.APSFrameConfig
オブジェクトと、オプションで APS ペイロード (ZCL レイヤー フレーム) をバイト単位 (2 文字) で受け入れ、APS フレームをバイト単位で出力します。次のコードは、前の節で作成した ZCL フレームの APS フレームを生成する方法を示します。
% IAS Zone Cluster apsConfigIntrusion = zigbee.APSFrameConfig( ... 'FrameType','Data', ... 'ClusterID',iasZoneClusterID, ... 'ProfileID',zigbee.profileID('Home Automation'), ... 'APSCounter',1, ... 'AcknowledgmentRequest',true); apsFrameIntrusion = zigbee.APSFrameGenerator(apsConfigIntrusion, ... zclFrameIntrusion); % On/Off cluster apsConfigOn = zigbee.APSFrameConfig('FrameType','Data', ... 'ClusterID',onOffClusterID, ... 'ProfileID',zigbee.profileID('Home Automation'), ... 'APSCounter',2, ... 'AcknowledgmentRequest',true); apsFrameOn = zigbee.APSFrameGenerator(apsConfigOn,zclFrameOn);
その他の調査
この例では、ドキュメンテーションにない以下のユーティリティを使用します。ドキュメンテーションにないユーティリティの API と機能は、将来変更される可能性があります。ユーティリティのソース コードを表示するには、関数edit
を使用します。
zigbee.APSFrameConfig
,zigbee.APSFrameGenerator
,zigbee.APSFrameDecoder
zigbee.ZCLFrameConfig
,zigbee.ZCLFrameGenerator
,zigbee.ZCLFrameDecoder
zigbee.IASZoneFrameConfig
,zigbee.IASZoneFrameGenerator
,zigbee.IASZoneFrameDecoder
参考文献
ZigBee Alliance, ZigBee Home Automation Public Application Profile, revision 29, v. 1.2, Jun. 2013.
ZigBee Alliance, ZigBee Specification Document 053474r17, 2007
IEEE 802.15.4-2011 - IEEE Standard for Local and Metropolitan Area Networks--Part 15.4: Low-Rate Wireless Personal Area Networks (LR-WPANs)
ZigBee Alliance, ZigBee Cluster Library Specification, Revision 6, Jan. 2016.