Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

ZigBee Smart Energy フレームの生成と復号化

この例では、Communications Toolbox™ を使用して、ZigBee® Smart Energy フレームを生成および復号化する方法を説明します。

背景

ZigBee 規格 [ 2 ] は、低速無線パーソナル エリア ネットワーク (LR-WPAN) のネットワーク (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 および ZCL "ヘッダー" はすべてのアプリケーション プロファイルと ZigBee クラスターに共通の形式 (それぞれ、[ 2 ] の Clause 2.2.5 および [ 4 ] の Clause 2.4 を参照) に従います。ZCL "ペイロード" は、一部のクラスターのみに使用され、クラスター固有の形式に従います。一般的な APS および ZCL ヘッダーの生成と復号化は、ZigBee ホーム オートメーション フレームの生成と復号化の例で説明しています。この例では、ZigBee smart energy ZCL ペイロードのクラスター特有の生成と復号化を説明します。

クラスターとコマンド

Smart Energy アプリケーション プロファイルで使用される 7 のクラスターのうち、この例では次のクラスターのフレームを生成および復号化します。

  1. Demand response and load control (DRLC) クラスター: このクラスターは、エネルギーの需要と消費への変更をアドバタイズします。この例では、"Load Control Event" コマンド (Clause 10.3.2.3.1 [ 4 ] で説明) のフレームの生成と復号化を説明します。

  2. Price クラスター: このクラスターは、エネルギー、ガス、水の価格設定情報を伝達します。この例では、"Get Current Price" コマンドおよび "Publish Price" コマンド (Clause 10.2.2.3.1 [ 4 ] で説明) のフレームの生成と復号化を説明します。

  3. Messaging クラスター: このクラスターは、ZigBee デバイス間でテキスト メッセージを交換します。この例では、"Display Message" コマンド (Clause 10.5.2.3.1 [ 4 ] で説明) のフレームの生成と復号化を説明します。

例示したコマンドに加えて、この例で提示した実装では次のコマンドのフレームの生成および復号化も行います。

DRLC クラスターの ZCL ペイロードの生成と復号化

zigbee.DRLCFrameConfig 構成オブジェクトは、Demand Response and Load Control (DRLC) クラスターの ZCL ペイロードの生成と復号化の両方で使用されます。このようなオブジェクトは、DRLC クラスターのペイロードと適用可能なすべてのプロパティを表します。関数 zigbee.DRLCFrameGenerator は、DRLC クラスターのペイロードを表す zigbee.DRLCFrameConfig オブジェクトを受け入れ、ペイロードをバイト単位で出力します。次のコードは、加熱デバイスに 23.5 C の指定値を設定するコマンドの ZCL ペイロードを作成します。

% Creation of DRLC cluster configuration object
drlcConfigTx = zigbee.DRLCFrameConfig( ...
    'CommandType','Load Control Event', ...
    'EventID','00000001', ...
    'DeviceClass','Strip Heaters/Baseboard Heaters', ...
    'HeatingSetPoint',23.5);

% DRLC cluster frame generation (ZCL payload)
drlcPayload = zigbee.DRLCFrameGenerator(drlcConfigTx);

関数 zigbee.DRLCFrameDecoder は、コマンド名とバイト単位の DRLC クラスターのペイロードを受け入れ、DRLC クラスターのペイロードを表す zigbee.DRLCFrameConfig オブジェクトを出力します。コマンド名は、ZCL ヘッダーの復号化から取得します。ZigBee ホーム オートメーション フレームの生成と復号化の例にある「ホーム オートメーション ZigBee 無線機の ZCL ヘッダーの復号化」のセクションを参照してください。

drlcConfigRx = zigbee.DRLCFrameDecoder( ...
    'Load Control Event',drlcPayload)
drlcConfigRx = 
  DRLCFrameConfig with properties:

         CommandType: 'Load Control Event'
             EventID: '00000001'
         DeviceClass: 'Strip Heaters/Baseboard Heaters'
         DeviceGroup: '00'
                Time: 0
            Duration: 0
    CriticalityLevel: 'Green'
     HeatingSetPoint: 23.5000
         RandomStart: 1
           RandomEnd: 1

Price クラスターの ZCL ペイロードの生成と復号化

zigbee.PriceFrameConfig 構成オブジェクトは、Price クラスターの ZCL ペイロードの生成と復号化の両方で使用されます。このようなオブジェクトは、Price クラスターのペイロードと適用可能なすべてのプロパティを表します。関数 zigbee.PriceFrameGenerator は、Price クラスターのペイロードを表す zigbee.PriceFrameConfig オブジェクトを受け入れ、ペイロードをバイト単位で出力します。次のコードは、商品の現在の価格を要求するコマンドの ZCL ペイロードを作成します。

% Creation of Price cluster configuration object
priceConfigTx = zigbee.PriceFrameConfig( ...
    'CommandType','Get Current Price');

% Price cluster frame generation (ZCL payload)
pricePayload = zigbee.PriceFrameGenerator(priceConfigTx);

関数 zigbee.PriceFrameDecoder は、コマンド名とバイト単位の Price クラスターのペイロードを受け入れ、Price クラスターのペイロードを表す zigbee.PriceFrameConfig オブジェクトを出力します。コマンド名は、ZCL ヘッダーの復号化から取得します。ZigBee ホーム オートメーション フレームの生成と復号化の例にある「ホーム オートメーション ZigBee 無線機の ZCL ヘッダーの復号化」のセクションを参照してください。

priceConfigRx = zigbee.PriceFrameDecoder( ...
    'Get Current Price',pricePayload)
priceConfigRx = 
  PriceFrameConfig with properties:

      CommandType: 'Get Current Price'
    IdleReceiving: 0

"Get Current Price" コマンドを受信すると、サーバーは "Publish Price" コマンドで応答します。

priceConfigTx = zigbee.PriceFrameConfig( ...
    'CommandType','Publish Price', ...
    'Price',0.4899, ...
    'Duration',14400);
pricePayload = zigbee.PriceFrameGenerator(priceConfigTx);

このときクライアント デバイスでは発行された価格を復号化することができます。

priceConfigRx = zigbee.PriceFrameDecoder( ...
    'Publish Price',pricePayload)
priceConfigRx = 
  PriceFrameConfig with properties:

       CommandType: 'Publish Price'
        ProviderID: 0
         RateLabel: ''
           EventID: 0
    GenerationTime: 0
              Unit: 'kW'
        UnitFormat: 'Binary'
          Currency: 840
         PriceTier: 1
      RegisterTier: 1
     NumPriceTiers: 0
         StartTime: 0
          Duration: 14400
             Price: 0.4899

Messaging クラスターの ZCL ペイロードの生成と復号化

zigbee.MessagingFrameConfig 構成オブジェクトは、Messaging クラスターの ZCL ペイロードの生成と復号化の両方で使用されます。このようなオブジェクトは、Messaging クラスターのペイロードと適用可能なすべてのプロパティを表します。関数 zigbee.MessagingFrameGenerator は、Messaging クラスターのペイロードを表す zigbee.MessagingFrameConfig オブジェクトを受け入れ、ペイロードをバイト単位で出力します。次のコードは、メッセージを表示するコマンドの ZCL ペイロードを作成します。

% Creation of messaging cluster configuration object
messageID = 1234;
messagingConfigTx = zigbee.MessagingFrameConfig( ...
    'CommandType','Display Message', ...
    'MessageID',messageID, ...
    'Message','This is a custom message', ...
    'Duration',90);

% Messaging cluster frame generation (ZCL payload)
displayMessagePayload = zigbee.MessagingFrameGenerator(messagingConfigTx);

関数 zigbee.MessagingFrameDecoder は、コマンド名とバイト単位の Messaging クラスターのペイロードを受け入れ、Messaging クラスターのペイロードを表す zigbee.MessagingFrameConfig オブジェクトを出力します。コマンド名は、ZCL ヘッダーの復号化から取得します。ZigBee ホーム オートメーション フレームの生成と復号化の例にある「ホーム オートメーション ZigBee 無線機の ZCL ヘッダーの復号化」のセクションを参照してください。

messagingConfigRx = zigbee.MessagingFrameDecoder( ...
    'Display Message',displayMessagePayload)
messagingConfigRx = 
  MessagingFrameConfig with properties:

            CommandType: 'Display Message'
              MessageID: 1234
       TransmissionType: 'Normal Transmission Only'
               Priority: 'Low'
    MessageConfirmation: 0
               Duration: 90
                Message: 'This is a custom message'

メッセージを表示するサーバーには、"Cancel Message" コマンドを使用してメッセージをキャンセルする機能もあります。

cancelMsgConfig = zigbee.MessagingFrameConfig( ...
    'CommandType','Cancel Message', ...
    'MessageID',messageID);
cancelMessagePayload = zigbee.MessagingFrameGenerator( ...
    messagingConfigTx);

このときクライアントでは "Cancel Message" コマンドを復号化することができます。

messagingConfigRx = zigbee.MessagingFrameDecoder( ...
    'Cancel Message',cancelMessagePayload)
messagingConfigRx = 
  MessagingFrameConfig with properties:

            CommandType: 'Cancel Message'
              MessageID: 1234
       TransmissionType: 'Normal Transmission Only'
               Priority: 'Low'
    MessageConfirmation: 0

Wireshark 復号化

生成した "Messaging" フレームは、PCAP 形式のファイルに変換し、Wireshark [ 5 ] で解析および可視化して、ZigBee 規格への準拠を検証できます。

PCAP ファイルでは、ZCL ペイロードがすべての他の層およびサブ層 (MAC、NET、APS、ZCL) のヘッダーと共に封入される必要があります。このタスクは次のコマンドによって実行されます。

zllProfileID = zigbee.profileID('Smart Energy'); % ZLL profile ID
msgClusterID = zigbee.clusterID('Messaging'); % Messaging cluster ID

payloadsWithInfo(1) = struct( ...
    'Payload',displayMessagePayload, ...
    'ProfileID',zllProfileID, ...
    'ClusterSpecific',true, ...
    'ClusterID',msgClusterID, ...
    'CommandType','Display Message', ...
    'Direction','Downlink');
payloadsWithInfo(2) = struct( ...
    'Payload',cancelMessagePayload, ...
    'ProfileID',zllProfileID, ...
    'ClusterSpecific',true, ...
    'ClusterID',msgClusterID, ...
    'CommandType','Cancel Message', ...
    'Direction','Downlink');
                           
% Add headers from other layers/sublayers:
MPDUs = zigbeeAddProtocolHeaders(payloadsWithInfo);

% Export MPDUs to a PCAP format
zigbeeExportToPcap(MPDUs,'zigbeeSmartEnergy.pcap');

% Open PCAP file with Wireshark

その他の調査

この例では、ドキュメンテーションにない以下のユーティリティを使用します。ドキュメンテーションにないユーティリティの API と機能は、将来変更される可能性があります。ユーティリティのソース コードを表示するには、関数editを使用します。

  • zigbee.DRLCFrameConfig, zigbee.DRLCFrameGenerator, zigbee.DRLCFrameDecoder

  • zigbee.PriceFrameConfig, zigbee.PriceFrameGenerator, zigbee.PriceFrameDecoder

  • zigbee.MessagingFrameConfig, zigbee.MessagingFrameGenerator, zigbee.MessagingFrameDecoder

参考文献

1- ZigBee Alliance, ZigBee Smart Energy Standard, Revision 19, Version 1.2a, December 3, 2014.

2 - ZigBee Alliance, ZigBee Specification Document 053474r17, 2007.

3 - IEEE 802.15.4-2011 - IEEE Standard for Local and Metropolitan Area Networks--Part 15.4: Low-Rate Wireless Personal Area Networks (LR-WPANs).

4 - ZigBee Alliance, ZigBee Cluster Library Specification, Revision 6, Jan. 2016.

5 - Wireshark software: https://www.wireshark.org/

関連するトピック