Specifies values for the properties of a device.
Usage notes
After IoT Platform sends a request to configure device properties, the device receives and processes the request in an asynchronous manner. When you call this operation, a success response indicates that IoT Platform sent a request. The response does not indicate that the device received and processed the request. After the device SDK responds to the request, the device properties are configured.
QPS limits
You can call this API operation up to 500 times per second per account.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | SetDeviceProperty | The operation that you want to perform. Set the value to SetDeviceProperty. |
Items | String | Yes | {"Switch":1,"Color":"blue"} | The properties that you want to configure. The properties must be in the JSON format. Each property consists of a combination of a property identifier and a property value in the key:value format. Separate multiple properties with commas (,). For example, you can configure the following properties for a smart lamp:
In this case, you can configure the following properties in the JSON format: Items={"Switch":1,"Color":"blue"} Note If you configure properties for the custom module testFb, specify Items={"testFb:Switch":1,"testFb:Color":"blue"} . The testFb module is not the default module. |
IotInstanceId | String | No | iot-v64***** | The ID of the instance. You can view the ID of the instance on the Overview page in the IoT Platform console. Important
For more information, see Overview. |
ProductKey | String | No | a1BwAGV**** | The ProductKey of the product to which the devices belong. Important If you specify a value for this parameter, you must configure the DeviceName parameter. |
DeviceName | String | No | light | The DeviceName of the device. Important If you configure this parameter, you must specify a value for the ProductKey parameter. |
IotId | String | No | Q7uOhVRdZRRlDnTLv****00100 | The ID of the device. The ID is a unique identifier that is issued by IoT Platform to the device. Important The IotId parameter specifies a GUID for the device. The value of the IotId parameter is equivalent to a combination of the values of the ProductKey and DeviceName parameters. If you specify a value for the IotId parameter, you do not need to specify values for the ProductKey and DeviceName parameters. If you specify values for the IotId, ProductKey, and DeviceName parameters, the value of the IotId parameter takes precedence. |
Qos | Integer | No | 1 | The quality of service (QoS) level of the message. Valid values:
|
In addition to the preceding operation-specific request parameters, you must configure common request parameters when you call this operation. For more information about common request parameters, see Common parameters.
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
Code | String | iot.system.SystemException | The error code returned if the call fails. For more information, see Error codes. |
Data | Struct | The data returned if the call is successful. | |
MessageId | String | abcabc123 | The ID of the message that IoT Platform sends to the device. |
ErrorMessage | String | A system exception occurred. | The error message returned if the call fails. |
RequestId | String | E55E50B7-40EE-4B6B-8BBE-D3ED55CCF565 | The ID of the request. |
Success | Boolean | true | Indicates whether the call was successful. Valid values:
|
Examples
Sample requests
https://iot.cn-shanghai.aliyuncs.com/?Action=SetDeviceProperty
&ProductKey=a1BwAGV****
&DeviceName=device1
&Items={"Switch":1,"Color":"blue"}
&<Common request parameters>
Sample success responses
XML
format
<SetDevicePropertyResponse>
<RequestId>57b144cf-09fc-4916-a272-a62902d5b207</RequestId>
<Success>true</Success>
<Data>
<MessageId>abcabc123</MessageId>
</Data>
</SetDevicePropertyResponse>
JSON
format
{
"RequestId":"57b144cf-09fc-4916-a272-a62902d5b207",
"Success": true,
"Data": {
"MessageId":"abcabc123"
}
}
Error codes
For a list of error codes, see Service error codes.