Updated on 2023-02-16 GMT+08:00

Platform Setting Device Properties

Function

This API is used by the platform to set properties of a device. The product model of a device defines the device properties that can be set by the platform. When a device receives a property setting request, the device needs to return the execution result to the platform. Otherwise, the request is considered to have timed out by the platform.

It is not suitable to report data in JSON format for devices with low configuration and limited resources or with limits on bandwidth usage. In this case, devices can transparently transmit the original binary data to the platform, but a codec is required to convert binary data to JSON format. For details about how to develop codecs, see Developing a Codec.

Topic

Downstream: $oc/devices/{device_id}/sys/properties/set/request_id={request_id}

Upstream: $oc/devices/{device_id}/sys/properties/set/response/request_id={request_id}

  • {request_id} is used to uniquely identify a request. If a device receives a downstream request with a topic carrying a request ID, the request ID must be included in the topic of the upstream response returned by the device.
  • 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/properties/set/#.

Downstream Request Parameters

Parameter

Mandatory or Optional

Type

Description

object_device_id

Optional

String

Identifies the device whose properties are to be set.

services

Mandatory

List<ServiceProperty>

Indicates a list of device services.

ServiceProperty structure

Parameter

Mandatory or Optional

Type

Description

service_id

Mandatory

String

Identifies a service of the device.

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.

Upstream Response Parameters

Parameter

Mandatory or Optional

Type

Description

result_code

Optional

Integer

Indicates the command execution result. 0 indicates a successful execution, whereas other values indicate an execution failure. If this parameter is not carried, the execution is considered to be successful.

result_desc

Optional

String

Describes the response to the request for setting properties.

Example Downstream Request

Topic: $oc/devices/{device_id}/sys/properties/set/request_id={request_id} 
Data format:
{
"object_device_id": "{object_device_id} ",
    "services": [{
            "service_id": "Temperature",
            "properties": {
                "value": 57,
                "value2": 60
            }
        },
        {
            "service_id": "Battery",
            "properties": {
                "level": 80,
                "level2": 90
            }
        }
    ]
}

Example Upstream Response

Topic: $oc/devices/{device_id}/sys/properties/set/response/request_id={request_id}
Data format:
{
    "result_code": 0,
    "result_desc": "success"
}