The package allows developers to write functions on Function Compute using python, which running within Link IoT Edge.
Here is a examle demonstrates publishing messages to a topic.
# -*- coding: utf-8 -*-
import logging
import lecoresdk
import time
it = lecoresdk.IoTData()
pub_params = {"topic": "/topic/hello",
"payload": "hello world"}
while True:
time.sleep(5)
it.publish(pub_params)
print("publish success")
# don't remove this function
def handler(event, context):
return 'hello world'
- IoTData#publish()
- IoTData#getThingProperties()
- IoTData#setThingProperties()
- IoTData#callThingService()
- IoTData#getThingsWithTags()
- Client#invoke_function()
- CredentialProviderChain()#get_credential()
Publishes messages.
The parameters are:
- params
dict
: which contains:- topic
str
(Required): the topic name to be published. - payload
str|bytes
(Required): the message payload in string or in binary.
- topic
Obtains specific properties of a thing.
The parameters are:
- params
dict
: which contains:- productKey
str
(Required): the productKey of the target thing from which to get properties. - deviceName
str
(Required) the deviceName of the target thing from which to get properties. - payload
list
(Required): a list of keys that specifies the properties to be obtained.
- productKey
- return:
- code
int
: if success it will return 0, or return error code. - output
dict
: return values. eg:{'property1':xxx, 'property2':yyy, ...}.
- code
Updates the properties of a thing.
The parameters are:
- params
dict
: which contains:- productKey
str
(Required): the productKey of the target thing to which to set properties. - deviceName
str
(Required): the deviceName of the target thing to which to set properties. - payload
dict
(Required): a dict consisting of keys and values that specifies the properties to be updated.eg, {"property1": "xxx", "property2": "yyy", ...}.
- productKey
- return:
- code
int
: if success it will return 0, or return error code. - output
dict
: customer data,if no data, it will return {}.
- code
Calls a specific service of a thing.
The parameters are:
- params
dict
: which contains:- productKey
str
(Required): the productKey of the target thing of which to call a service. - deviceName
str
(Required): the deviceName of the target thing of which to call a service. - service
str
(Required): the name of the service to be called. - payload
str|bytes
: a optional string or binary in JSON that you provided to the service as arguments.
- productKey
- return:
- code
int
: if success it will return 0, or return error code. - output
dict
: return values. eg:{"key1": "xxx", "key2": "yyy", ...}.
- code
Obtains a list of thing objects, each of which being with all given tags.
The parameters are:
- params
dict
: which contains:- payload
list
(Required): a list oftag
that consisting of dict{key: value}
. eg:[{"key":"value"}]
- payload
- return:
- contains a list of device match the tags. eg, [{"productKey":"xxx", "deviceName":"yyy"}].
Invokes a specific function.
The parameters are:
- params
dict
: which contains:- functionId
str
(Required): the id of the function to be invoked. Function name is not supported currently. - invocaionType
str
: a optional type of the invocation, may beSync
orAsync
. It will beSync
if not specified. - invokerContext
str
: a optional invoker-specific information to the invoked function. The invoker information will be passed into the function, and can be choosed through context variable. It must be base64-encoded. - payload
str|bytes
: a optional string or binary data that you want to provide to the function as input.
- functionId
get credential data.
- return
dict
: get credential data. eg, {"accessKeyId":"xxx", "accessKeySecret", "yyy", "securityToken", "zzz"}
Apache 2.0