Skip to content

Latest commit

 

History

History
134 lines (99 loc) · 4.52 KB

File metadata and controls

134 lines (99 loc) · 4.52 KB

Link IoT Edge Core SDK for Python

The package allows developers to write functions on Function Compute using python, which running within Link IoT Edge.

Example

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'

APIs


IoTData.publish(params)

Publishes messages.

The parameters are:

  • paramsdict: which contains:
    • topicstr(Required): the topic name to be published.
    • payloadstr|bytes(Required): the message payload in string or in binary.

IoTData.getThingProperties(params)

Obtains specific properties of a thing.

The parameters are:

  • paramsdict: which contains:
    • productKeystr(Required): the productKey of the target thing from which to get properties.
    • deviceNamestr (Required) the deviceName of the target thing from which to get properties.
    • payloadlist(Required): a list of keys that specifies the properties to be obtained.
  • return:
    • codeint: if success it will return 0, or return error code.
    • outputdict: return values. eg:{'property1':xxx, 'property2':yyy, ...}.

IoTData.setThingProperties(params)

Updates the properties of a thing.

The parameters are:

  • paramsdict: which contains:
    • productKeystr(Required): the productKey of the target thing to which to set properties.
    • deviceNamestr(Required): the deviceName of the target thing to which to set properties.
    • payloaddict(Required): a dict consisting of keys and values that specifies the properties to be updated.eg, {"property1": "xxx", "property2": "yyy", ...}.
  • return:
    • codeint: if success it will return 0, or return error code.
    • outputdict: customer data,if no data, it will return {}.

IoTData.callThingService(params)

Calls a specific service of a thing.

The parameters are:

  • paramsdict: which contains:
    • productKeystr(Required): the productKey of the target thing of which to call a service.
    • deviceNamestr(Required): the deviceName of the target thing of which to call a service.
    • servicestr(Required): the name of the service to be called.
    • payloadstr|bytes: a optional string or binary in JSON that you provided to the service as arguments.
  • return:
    • codeint: if success it will return 0, or return error code.
    • outputdict: return values. eg:{"key1": "xxx", "key2": "yyy", ...}.

IoTData.getThingsWithTags(params)

Obtains a list of thing objects, each of which being with all given tags.

The parameters are:

  • paramsdict: which contains:
    • payloadlist(Required): a list of tag that consisting of dict {key: value}. eg:[{"key":"value"}]
  • return:
    • contains a list of device match the tags. eg, [{"productKey":"xxx", "deviceName":"yyy"}].

Client.invoke_function(params)

Invokes a specific function.

The parameters are:

  • paramsdict: which contains:
    • functionIdstr(Required): the id of the function to be invoked. Function name is not supported currently.
    • invocaionTypestr: a optional type of the invocation, may be Sync or Async. It will be Sync if not specified.
    • invokerContextstr: 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.
    • payloadstr|bytes: a optional string or binary data that you want to provide to the function as input.

CredentialProviderChain().get_credential()

get credential data.

  • returndict: get credential data. eg, {"accessKeyId":"xxx", "accessKeySecret", "yyy", "securityToken", "zzz"}

License

Apache 2.0