Link IoT Edge provides the SDK for Python. The SDK is named lethingaccesssdk. This topic describes how to use the SDK for Python.
For more information about the source code of the SDK, visit Open-source SDK for Python.
Installation and usage
Config
The information related to driver configurations.
- Config()
Constructs a new Config object based on a configuration string.
- getThingInfos()
Returns all device-related information.
The return values are described as follows:
Returns the encapsulated configuration information that the device uses to connect to Link IoT Edge.
Table 1. Response Parameters Parameter Type Description ThingInfo List The device information. Table 2. ThingInfo description Parameter Type Description productKey String The unique identifier of the product. deviceName String The name of the device. custom Object The custom device configurations. - getDriverInfo()
Returns the driver information.
Response:dict
ThingCallback
Create a class (for example, Demo_device) that inherits ThingCallback based on the physical device. Then implement the setProperties, getProperties, and callService functions in the class (Demo_device).
- setProperties
Sets device properties.
Table 3. Request Parameters Parameter Type Description properties Dict The property object. The format of the property value is as follows: { "property1": "value1", "property2": "value2" }
Table 4. Response Parameters Parameter Type Description code Integer If the request is successful, 0 is returned. If the request fails, a non-zero error code is returned. output Dict The returned data. You can customize the content. Example: { "key1": xxx, "key2": yyy, ... }
If no data is returned,
{}
is returned. - getProperties
Obtains device properties.
Table 5. Request Parameters Parameter Type Description keys List The names of the properties. The format is as follows: ['key1', 'key2']
Table 6. Response Parameters Parameter Type Description code Integer If the request is successful, 0 is returned. If the request fails, a non-zero error code is returned. output Dict The return value. Example: { 'property1': xxx, 'property2': yyy, ..}. }
- callService
Calls a device service.
Table 7. Request Parameters Parameter Type Description name String The name of the device service. args Dict The list of service input parameters. The format is as follows: { "key1": "value1", "key2": "value2" }
Table 8. Response Parameters Parameter Type Description code Integer If the request is successful, 0 is returned. If the request fails, a non-zero error code is returned. output Dict The returned data. You can customize the content. Example: { "key1": xxx, "key2": yyy, ... }
If no data is returned,
{}
is returned.
ThingAccessClient(config)
The client that allows devices to connect to IoT Platform. You can use the client to report properties and events. You can also use the client to send commands from the cloud to the devices.
Parameter | Type | Description |
---|---|---|
config | Dict | The productKey and deviceName assigned by IoT Platform.
Example:
|
- registerAndOnline(ThingCallback)
Registers the device on the gateway and notifies the gateway to connect the device to IoT Platform. You must register and connect the devices to IoT platform before they can receive commands from or send data to IoT platform.
Table 10. Request Parameters Parameter Type Description ThingCallback Object The callback object of the device. - reportProperties(properties)Reports device properties to IoT Platform.
Table 11. Request Parameters Parameter Type Description properties Dict The keys and values in the properties. The format is as follows: { "key1": "value1", "key2": "value2" }
- reportEvent(eventName, args)Reports device events to IoT Platform.
Table 12. Request Parameters Parameter Type Description eventName String The event name, which is the same as the name of the event you specified in the product definition. args Dict The keys and values in the event. The format is as follows: { "key1": "value1", "key2": "value2" }
- getTsl()
Returns the TSL string of the device. The data format is the same as in IoT Platform.
Response:A TSL string
- getTslExtInfo()
Returns the extended information of the TSL.
Response:The extended information of the TSL.
- online()
Notifies the gateway that the device is online. The interface is used when the device is offline and then is online again.
- offline()
Notifies the gateway that the device is offline.
- cleanup()
Recycles resources. You can use this interface to free up resources.
- unregister()
Unbinds a device from a gateway. Use this interface with caution.
getConfig()
Obtains information related to driver configurations.
The return value is a driver configuration string.