Obtains the value of a property for a specified device.
getThingProperties(params)
Parameter | Type | Description |
---|---|---|
params | dict | The request parameter object. For more information, see the table Parameter descriptions of params. |
Parameter | Type | Description |
---|---|---|
productKey | String | The key of the product to which the device belongs. It is a unique identifier issued by IoT Platform for the product. |
deviceName | String | The name of the device. The device name is generated when the device is created. |
payload | List |
The array of identifiers for the device properties that you want to obtain. A successful call will return the current corresponding value of the property. Log on to the IoT Platform console. On the Define Feature tab of the product details page, click TSL Model to view the identifier of each service. |
Parameter | Type | Description |
---|---|---|
return | dict | If the call is successful, the property values of the device are returned. Otherwise, the error message reported by the device driver is returned. |
Sample requests
The following example obtains the LightSwitch property value of the LightDev2 device (whether the device is switched on).
# -*- coding: utf-8 -*-
import lecoresdk
lesdk = lecoresdk.IoTData()
def handler(event, context):
get_params = {"productKey": "a1ZJTVsqj2y", # Please replace it with your Product Key.
"deviceName": "LightDev2", # Please replace it with your Device Name.
"payload": ["LightSwitch"]} # The property defined in the Product TSL.
res = lesdk.getThingProperties(get_params)
print(res)
if 'LightSwitch' in res.keys():
print("-- [Success] LightSwitch = %s" % res['LightSwitch'])
if res['LightSwitch'] == '0':
print("-- Light is off.")
else:
print("-- Light is on.")
else:
print("-- [Warn] No property LightSwitch return.");
return 'OK'