全部产品
云市场

API列表

更新时间:2019-02-27 20:01:21

Init & Config

enable_logger

  1. enable_logger(level)

Description:

enable linkkit sdk internal log

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Input Parameter

level

type:logging.CRITICALlogging.FATALlogging.ERRORlogging.WARNINGlogging.WARNlogging.INFOlogging.DEBUG

Return Value

None

Exception

No Exception

disable_logger

  1. disable_logger()

Description:

disable linkkit sdk internal log

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Input Parameter

No input parameter

Return Value

None

Exception

No Exception

LinkKit

  1. LinkKit(self, host_name, product_key, device_name, device_secret,
  2. product_secret=None,user_data=None)

Description:

construct a LinkKit object

Available Working State:

None

Input Parameter

host_name

product_key

  • type:string
  • description:key of product,get from IoT Console

device_name

  • type:string
  • description:name of device,get from IoT Console

device_secret

  • type:string
  • description:secret of device,get from IoT Console,or use dynamic register device

product_secret

  • type:string
  • description:secret of product,get from IoT Console

user_data

  • type:object
  • description:user data,LinkKit all callback function give this user_data as last parameter

Return Value

LinkKit object

Exception

  • type:ValueError

config_mqtt

  1. config_mqtt(self, port=1883, protocol="MQTTv311", transport="TCP",
  2. secure="TLS", keep_alive=60, clean_session=True,
  3. max_inflight_message=20, max_queued_message=0,
  4. auto_reconnect_min_sec=1,
  5. auto_reconnect_max_sec=60,
  6. cadata=None):

Description:

config mqtt connect parameter

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Input Parameter

port
  • type:int
  • description:port of mqtt broker
protocol
  • type:string
  • description:version of mqtt protocol.available:”MQTTv311”,”MQTTv31”
transport
  • type:string
  • description:transport layer type:only “TCP” support currently
secure
  • type:string
  • description:secure type,available:”TLS”,use TLS1.2;””:use bare TCP,no secure
keep_alive
  • type:int
  • description: heartbeat of mqtt connect,unit is second
clean_session
  • type:bool
  • description:is clean session
max_inflight_message
  • type:int
  • description:max inflight message count in sdk internal buffer
max_queued_message
  • type:int
  • description:max received message count in sdk internal buffer,0 mean no limit
auto_reconnect_min_sec
  • type:int
  • description:auto reconnect wait min seconds,available range(1~120*60)
auto_reconnect_max_sec
  • type:int
  • description:auto reconnect wait max seconds,available range(1~120*60);
  • auto_reconnect_max_sec must >= auto_reconnect_min_sec
cadata
  • type:string
  • description:ca file content use in SSL secure context

Return Value

None

Exception

  • type:ValueError

config_device_info

  1. config_device_info(interface_info)

Description:

config device info,only support interface info currently

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Input Parameter

interface_info

  • type:string
  • description:interface info

Return Value

rcrc:type:int0 success1 interface info too long,must less than 160 chars

Exception

ValueError: not string

destruct

  1. destruct()

Description:

destruct a LinkKit object,will block wait for internal thread and object exit and destroy finish

Available Working State:

Any except LinkKit.LinkKitState.DESTRUCTED

Input Parameter

None

Return Value

None

Exception

None

connect_async

  1. connect_async()

Description:

connect async,start internal working thread

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Input Parameter

None

Return Value

  • rc
  • rc:int 0 start working thread success 1 working thread already running

Exception

LinkKit.StateError

disconnect

  1. disconnect()

Description:

disconnect mqtt

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

None

Return Value

None

Exception

LinkKit.StateError

Topic Management

publish_topic

  1. publish_topic(topic, payload=None, qos=1)

Description:

publish a topic message to broker

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

topic
  • type:string
  • description:mqtt topic
payload
  • type:string
  • description:mqtt message send data
qos
  • type:int
  • description:mqtt message qos value,available 0,1

Return Value

  • rc, mid
  • rc:int 0 publish topic success 1 publish fail
  • mid:int message id

Exception

  • LinkKit.StateError
  • ValueError

subscribe_topic

  1. subscribe_topic(topic, qos=1)

Description:

subscribe topic

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

topic
  • type:string
  • description: mqtt topic or
  • type:list(topic,qos)
  • description:when subscribe multiple topics,can use list parameter to topic,qos will ignore
qos
  • type:int
  • description:mqtt message qos value,available 0,1 or
  • if topic is list,this value ignore

Return Value

  • rc, mid
  • rc:int 0 subscribe topic success, 1 subscribe fail
  • mid:int message id

Exception

  • LinkKit.StateError
  • ValueError

unsubscribe_topic

  1. unsubscribe_topic(topic)

Description:

unsubscribe topics

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

topic
  • type:string
  • description: mqtt topic or
  • type:list(topic)
  • description:when unsubscribe multiple topics,can use list parameter to topic

Return Value

  • rc, mid
  • rc:int 0 unsubscribe topic success, 1 unsubscribe fail
  • mid:int message id

Exception

  • LinkKit.StateError
  • ValueError

check_state

  1. check_state()

Description:

get current working state

Available Working State:

Any

Input Parameter

None

Return Value

  • LinkKit.LinkKitState.INITIALIZED
  • LinkKit.LinkKitState.CONNECTING
  • LinkKit.LinkKitState.CONNECTED
  • LinkKit.LinkKitState.DISCONNECTING
  • LinkKit.LinkKitState.DISCONNECTED
  • LinkKit.LinkKitState.DESTRUCTING
  • LinkKit.LinkKitState.DESTRUCTED

Exception

None

Thing Management

thing_setup

  1. thing_setup(file=None)

Description:

setup thing model

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Input Parameter

file
  • type:string
  • description:thing model json file path,if set to None,thing only support custom protocol

Return Value

rc

  • type:int
  • 0 success,1 already set,2 file open fail

Exception

  • LinkKit.StateError

thing_trigger_event

  1. thing_trigger_event(event_tuple)

Description:

send a event to broker

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

event_tuple
  • type:tuple(event, params)
  • description:event is event identifier in things model,params is dict object and structure corresponding to thing model

Return Value

  • rc, request_id
  • rc:int 0 success,1 fail
  • request_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_post_property

  1. thing_post_property(property_data)

Description:

upload property values to broker

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

property_data
  • type:dict
  • description:property_data structure corresponding to thing model

Return Value

  • rc, request_id
  • rc:int 0 success,1 fail
  • request_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_post_property

  1. thing_post_property(property_data)

Description:

upload property values to broker

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

property_data
  • type:dict
  • description:property_data structure corresponding to thing model

Return Value

  • rc, request_id
  • rc:int 0 success,1 fail
  • request_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_update_tags

  1. thing_update_tags(tag_map)

Description:

update tags of the thing

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

tag_map
  • type:dict
  • description: tag map

Return Value

  • rc, request_id
  • rc:int 0 success,1 fail
  • request_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_remove_tags

  1. thing_remove_tags(tag_list)

Description:

remove tags of the thing

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

tag_list
  • type:list
  • description: the list of the tag keys

Return Value

  • rc, request_id
  • rc:int 0 success,1 fail
  • request_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_update_shadow

  1. thing_update_shadow(reported, version)

Description:

update shadow of the thing

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

reported
  • type: dict
  • description: reported items
  • example
    1. reported = {"color":"red"}
version
  • type: int
  • description: the version of the shadow

Return Value

  • rc, message_id
  • rc:int 0 success,1 fail
  • message_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_get_shadow

  1. thing_get_shadow()

Description:

get shadow of the thing

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

Return Value

  • rc, message_id
  • rc:int 0 success,1 fail
  • message_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

local_get_latest_shadow

  1. local_get_latest_shadow()

Description:

get shadow of the thing from the local cache

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

Return Value

  • shadow data

Exception

  • LinkKit.StateError

subscribe_rrpc_topic

  1. subscribe_rrpc_topic(topic)

Description:

subscribe the RRPC topic

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

topic
  • type: string
  • description: topic name

Return Value

  • rc, message_id
  • rc:int 0 success,1 fail
  • message_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

unsubscribe_rrpc_topic

  1. unsubscribe_rrpc_topic(topic)

Description:

unsubscribe the RRPC topic

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

topic
  • type: string
  • description: topic name

Return Value

  • rc, message_id
  • rc:int 0 success,1 fail
  • message_id:string when rc is 0,this value represent this request

Exception

  • LinkKit.StateError

thing_answer_service

  1. thing_answer_service(identifier, request_id, code, data=None)

Description:

answer service reply

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

identifier
  • type:string
  • description:service identifier of thing model
request_id
  • type:string
  • description:request id string for this call
code
  • type:string
  • description:broker response code for this request
data
  • type:string
  • description:answer service data

Return Value

rc
  • type:int
  • description:0 success, 1 fail

Exception

  • LinkKit.StateError

thing_answer_rrpc

  1. thing_answer_rrpc(identifier, id, response)

Description:

reply the response of RRPC request

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

id
  • type:string
  • description: request id

response

  • type:string
  • description: the payload of the response

Return Value

rc
  • type:int
  • description:0 success, 1 fail

Exception

  • LinkKit.StateError

thing_raw_post_data

  1. thing_raw_post_data(payload)

Description:

send raw bytes data to broker

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

payload
  • type:string
  • description:raw data to broker

Return Value

rc
  • type:int
  • description:0 success, 1 fail

Exception

  • LinkKit.StateError

thing_raw_data_reply

  1. thing_raw_data_reply(payload)

Description:

send reply through raw data to broker

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Input Parameter

payload
  • type:string
  • description:raw data to broker for reply

Return Value

rc
  • type:int
  • description:0 success, 1 fail

Exception

  • LinkKit.StateError

on_publish_topic

  1. on_publish_topic(mid, userdata)

Description:

callback after publish_topic call

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

mid
  • type:int
  • description:publish message id
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_subscribe_topic

  1. on_subscribe_topic(mid, granted_qos, userdata)

Description:

callback after subscribe_topic call

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

mid
  • type:int
  • description:publish message id
granted_qos
  • type:list(int)
  • description: corresponding to subscribe_topic parameter topic,0 represent qos=0,1 represent qos=1,128 represent subscribe error
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_unsubscribe_topic

  1. on_unsubscribe_topic(mid, userdata)

Description:

callback after unsubscribe topic

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

mid
  • type:int
  • description:publish message id
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_connect

  1. on_connect(session_flag, rc, userdata)

Description:

callback after connect_async

Available Working State:

  • LinkKit.LinkKitState.INITIALIZED

Callback Parameter

session_flag
  • type:int
  • description:is previous connect session,0 new session; 1 previous session
rc
  • type:int
  • description:
  1. 0: Connection successful
  2. 1: Connection refused - incorrect protocol version
  3. 2: Connection refused - invalid client identifier
  4. 3: Connection refused - server unavailable
  5. 4: Connection refused - bad username or password
  6. 5: Connection refused - not authorised
  7. 6: SSL wrong - ca file/data wrong
  8. 7: MQTT parameter wrong
  9. 8: Connect Timeout
  10. 9: network error
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_device_dynamic_register

  1. on_device_dynamic_register(rc, value, userdata)

Description:

dynamic register callback

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

rc
  • type:int
  • description:0 register success,1 register fail
value
  • type:string
  • description:when rc==0,value is device secret,when rc !=0,value is return message
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_raw_data_post

  1. on_thing_raw_data_post(payload, userdata)

Description:

callback after thing_raw_data_post done

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

payload
  • type:string
  • description:mqtt message received data
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_raw_data_arrived

  1. on_thing_raw_data_arrived(payload, userdata)

Description:

callback when raw data received

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

payload
  • type:string
  • description:mqtt message received data
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_event_post

  1. on_thing_event_post(event, request_id, code, data, message, userdata)

Description:

callback after thing_trigger_event call

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

event
  • type:string
  • description:event is event identifier in things model
request_id
  • type:string
  • description: request_id same as return value of thing_trigger_event
code
  • type:int
  • description: broker response code,200 success,other value wrong occur
data
  • type:dict
  • description: broker response data
message
  • type:string
  • description: message corresponding broker response code
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_prop_post

  1. on_thing_prop_post(request_id, code, data, message,userdata)

Description:

callback after thing_post_property

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

request_id
  • type:string
  • description: request_id same as return value of thing_post_property
code
  • type:int
  • description: broker response code,200 success,other value wrong occur
data
  • type:dict
  • description: broker response data
message
  • type:string
  • description: message corresponding broker response code
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_disconnect

  1. on_disconnect(rc)

Description:

callback after connection disconnect

Available Working State:

  • LinkKit.LinkKitState.DISCONNECTED

Callback Parameter

rc
  • type:int
  • description:0 success call for disconnect,1 network error
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_enable

  1. on_thing_enable(userdata)

Description:

callback for things api able to call

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_disable

  1. on_thing_disable(userdata)

Description:

callback when things model disabled

Available Working State:

  • LinkKit.LinkKitState.DISCONNECTED

Callback Parameter

userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

None

Exception

None

on_thing_call_service

  1. on_thing_call_service(identifier, request_id, params, userdata)

Description:

callback after receiver call service request

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

identifier
  • type:string
  • description:identifier is service identifier in things model
request_id
  • type:string
  • description: request_id represent this service call
params
  • type:dict
  • description: params structure corresponding to thing model service define
userdata
  • type:
  • description:same as LinkKit input parameter user_data

Return Value

Exception

on_thing_prop_changed

  1. on_thing_prop_changed(params, userdata)

Description:

callback after receive broker set property message

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

params
  • type:dict
  • description: params structure corresponding to thing model property define

Return Value

None

Exception

None

on_thing_shadow_get

  1. on_thing_shadow_get(payload, userdata)

Description:

callback after get the shadow

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

payload
  • type:dict
  • description: payload of the shadow

Return Value

None

Exception

None

on_topic_rrpc_message

  1. on_topic_rrpc_message(id, topic, payload, qos, userdata)

Description:

callback for rrpc messages

Available Working State:

  • LinkKit.LinkKitState.CONNECTED

Callback Parameter

id
  • type: string
  • description: request id
topic
  • type:string
  • description: the topic name
qos
  • type:int
  • description: QoS value

Return Value

None

Exception

None