デバイスシャドウ JSON ファイルの形式

形式は次のとおりです。

{
"state": {
"desired": {
"attribute1": integer2,
"attribute2": "string2",
...
"attributeN": boolean2
},
"reported": {
"attribute1": integer1,
"attribute2": "string1",
...
"attributeN": boolean1
}
},
"metadata": {
"desired": {
"attributes": {
"timestamp": timestamp
},
"attributes": {
"timestamp": timestamp
},
...
"attributes": {
"timestamp": timestamp
}
},
"reported": {
"attributes": {
"timestamp": timestamp
},
"attributes": {
"timestamp": timestamp
},
...
"attributes": {
"timestamp": timestamp
}
}
},
"timestamp": timestamp,
"version": version
}
JSON のプロパティについては、表 1 で説明します。
表 1. JSON のプロパティ
プロパティ 説明
desired デバイスに対して希望するステータス。

アプリケーションは、デバイスにアクセスせずに、デバイスの desired プロパティを書き込みます。

reported デバイスが報告したステータス。 デバイスは、reported プロパティにデータを書き込むことで、最新のステータスを報告します。

アプリケーションは、このプロパティを読み取ることによってデバイスのステータスを取得します。

metadata デバイスシャドウサービスは、デバイスシャドウ JSON ファイルの更新に従って、メタデータ (metadata) を自動的に更新します。

デバイスシャドウ JSON ファイルの State メタデータには、各プロパティのタイムスタンプ (timestamp) が含まれています。 タイムスタンプは、正確な更新時刻を取得するためのもので、エポック時刻 (1970-01-01 00:00:00 UTC からの経過秒数) で表されます。

timestamp デバイスシャドウ JSON ファイルの最終更新時刻。
version デバイスシャドウのバージョン更新をリクエストすると、デバイスシャドウは、リクエストされたバージョンが現在のバージョンよりも新しいかどうかを確認します。

リクエストされたバージョンが現在のものよりも新しい場合、デバイスシャドウは、リクエストされたバージョンに更新します。 そうでない場合、デバイスシャドウはリクエストを却下します。

バージョン番号は、バージョンの更新に従って増加し、最新のデバイスシャドウ JSON ファイルのバージョンを維持します。

デバイスシャドウ JSON ファイルの例:

{
"state" : {
"desired" : {
"color" : "RED",
"sequence" : [ "RED", "GREEN", "BLUE" ]
},
"reported" : {
"color" : "GREEN"
}
},
"metadata" : {
"desired" : {
"color" : {
"timestamp" : 1469564492
},
"sequence" : {
"timestamp" : 1469564492
}
},
"reported" : {
"color" : {
"timestamp" : 1469564492
}
}
},
"timestamp" : 1469564492,
"version" : 1
}

空のプロパティ

  • デバイスシャドウ JSON ファイルには、desired ステータスが指定された場合にのみ、desired プロパティが含まれます。 次のデバイスシャドウ JSON ファイルには desired プロパティが含まれていませんが、有効です。
    
    {
    "state" : {
    "reported" : {
    "color" : "red",
    }
    },
    "metadata" : {
    "reported" : {
    "color" : {
    "timestamp" : 1469564492
    }
    }
    },
    "timestamp" : 1469564492,
    "version" : 1
    }
  • 次のデバイスシャドウ JSON ファイルには reported プロパティが含まれていませんが、有効です。
    
    {
    "state" : {
    "desired" : {
    "color" : "red",
    }
    },
    "metadata" : {
    "desired" : {
    "color" : {
    "timestamp" : 1469564492
    }
    }
    },
    "timestamp" : 1469564492,
    "version" : 1
    }

配列

デバイスシャドウ JSON ファイルは、配列を使用することができます。更新が必要なときには、配列全体を更新する必要があります。

  • 初期状態:
    
    {
    "reported" : { "colors" : ["RED", "GREEN", "BLUE" ] }
    }
  • 更新:
    
    {
    "reported" : { "colors" : ["RED"] }
    }
  • 最終状態:
    
    {
    "reported" : { "colors" : ["RED"] }
    }