Updated on 2024-12-02 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. For the details of the API, see Modify Device Properties. 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}

  • When an application modifies device properties, the platform generates a unique ID to identify the request. This ID is carried in request_id in the downstream topic of the platform-side device property configuration.
  • The device cannot detect the request_id in advance. When a device subscribes to a topic that ends with request_id={request_id}, 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/Optional

Type

Description

object_device_id

Optional

String

Explanation:

  • For directly connected device: This parameter is not carried.
  • For gateway child device: The value is the child device ID in the topic.

services

Mandatory

List<ServiceProperty>

Indicates a list of device services.

ServiceProperty structure

Parameter

Mandatory/Optional

Type

Description

service_id

Mandatory

String

Explanation:

Service ID of the device, which is determined by the product model.

properties

Mandatory

Object

Explanation:

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/Optional

Type

Description

result_code

Optional

Integer

Explanation:

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

Explanation:

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"
}