Updated on 2024-11-06 GMT+08:00

Device Obtaining Device Shadow Data from the Platform

Function

This API is used by a device to obtain device shadow data from IoTDA. You can configure desired data in a device shadow through an application or the platform. When a device goes online and subscribes to this topic, the device can obtain the device shadow data from the platform and synchronize the desired device properties.

The interaction logic is described as follows:

1. The application calls the API for configuring desired properties in a device shadow or configures the device shadow data on the console.

2. The device (which has subscribed to the corresponding topic) proactively sends a request to obtain the device shadow data from the platform.

3. The platform responds to the device request and returns the device shadow data.

4. The device parses the desired properties and modifies device properties.

Topic

Upstream: $oc/devices/{device_id}/sys/shadow/get/request_id={request_id}

Downstream: $oc/devices/{device_id}/sys/shadow/get/response/request_id={request_id}

  • {request_id} is used to uniquely identify a request. If this parameter is carried in a message sent by a device, ensure that the parameter value is unique on the device by using an incremental number or UUID.
  • When a device subscribes to a topic that ends with request_id={request_id}, such as the downstream topic mentioned above, the number sign (#) can be used to replaced request_id={request_id}, for example, $oc/devices/{device_id}/sys/shadow/get/response/#.

Upstream Request Parameters

Parameter

Mandatory or Optional

Type

Description

object_device_id

Optional

String

Identifies a device that requests its device shadow.

service_id

Optional

String

Identifies a service of the device that requests the device shadow. If this parameter is not specified, device shadow data of all services will be returned.

Downstream Response Parameters

Parameter

Mandatory or Optional

Type

Description

object_device_id

Mandatory

String

Identifies a device that requests its device shadow.

shadow

Optional

List<ShadowData>

Indicates the shadow data.

ShadowData structure

Parameter

Mandatory or Optional

Type

Description

service_id

Mandatory

String

Identifies a service of the device.

desired

Optional

PropertiesData

Indicates the property list in the desired section of the device shadow.

reported

Optional

PropertiesData

Indicates the property list in the reported section of the device shadow.

version

Optional

Integer

Indicates the device shadow version.

PropertiesData structure

Parameter

Mandatory or Optional

Type

Description

properties

Mandatory

Object

Indicates the property list of the device service. Multiple property parameters can be defined in the product model associated with the device.

event_time

Optional

String

Indicates the UTC time of the device property data. The format is yyyyMMdd'T'HHmmss'Z', for example, 20161219T114920Z.

Example Upstream Request

Topic: $oc/devices/{device_id}/sys/shadow/get/request_id={request_id} 
Data format:
{
	"object_device_id": "40fe3542-f4cc-4b6a-98c3-61a49ba1acd4",
	"service_id": "WaterMeter"
}

Example Downstream Response

Topic: $oc/devices/{device_id}/sys/shadow/get/response/request_id={request_id}
Data format:
{
  "object_device_id": "40fe3542-f4cc-4b6a-98c3-61a49ba1acd4",
  "shadow": [
    {
      "service_id": "WaterMeter",
      "desired": {
        "properties": {
          "temperature": "60"
        },
        "event_time": "20151212T121212Z"
      },
      "reported": {
        "properties": {
          "temperature": "60"
        },
        "event_time": "20151212T121212Z"
      },
      "version": 1
    }
  ]
}