Device Shadow를 사용하면 Device가 네트워크에 연결되지 않은 경우에도 Device의 상태를 사용 할 수 있습니다.
$aws/things/+/shadow/update/delta
$aws/things/+/shadow/update/accepted
모든 shadow는 예약된 MQTT Topic과 HTTP URL을 이용하여 Get, Update, Delete와 같은 action을 할 수 있습니다.
-
desired: 사용자가 원하는 상태 (Apps specify the desired states of device properties by updating the desired object)
-
reported: Thing 보고한 현재 상태 (Devices report their current state in the reported object)
-
delta: desired와 reported가 서로 다른 상태 (AWS IoT reports differences between the desired and the reported state in the delta object
{
"state": {
"desired": {
"color": "RED",
"state": "STOP"
},
"reported": {
"color": "GREEN",
"engine": "ON"
},
"delta": {
"color": "RED",
"state": "STOP"
}
},
"metadata": {
"desired": {
"color": {
"timestamp": 12345
},
"state": {
"timestamp": 12345
}
},
"reported": {
"color": {
"timestamp": 12345
},
"engine": {
"timestamp": 12345
}
},
"delta": {
"color": {
"timestamp": 12345
},
"state": {
"timestamp": 12345
}
}
},
"version": 17,
"timestamp": 123456789
}
}
아래와 같이 BLUE에서 RED, GREEN으로 state를 변경하려는 요청이 순차적으로 내려갈 경우에 device에서는 마지막 state를 version으로 받아 들여서 사용할 수 있습니다.
{
"state": {
"reported": {
"color": "blue"
}
},
"version": 9,
"timestamp": 123456776
}
{
"state": {
"desired": {
"color": "RED"
}
},
"version": 10,
"timestamp": 123456777
}
{
"state": {
"desired": {
"color": "GREEN"
}
},
"version": 11,
"timestamp": 123456778
}
Device가 offline에서 online으로 변경되었을때 Update2가 먼저 도달하고, 이후에 Update1이 도달하면, version을 보고 이전 값인 경우에 discard 할 수 있습니다.
How to Get Started with Device Shadows for AWS IoT Core
AWS Tutorials - Understanding Device Shadow Service in AWS IoT Core