2021-05-26 10:59:33 +08:00

328 lines
6.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## API 参考文档
主要的 API 参考文档如下:
#### from uiotedgedriverlinksdk
- **[getLogger()](#getLogger)**
---
#### from uiotedgedriverlinksdk.client
- **[getConfig()](#getConfig)**
- **[Config()](#Config)**
- Config#**[getDeviceInfos()](#getDeviceInfos)**
- Config#**[getDriverInfo()](#getDriverInfo)**
---
#### from uiotedgedriverlinksdk.exception
- BaseEdgeException
- EdgeDriverLinkException
- EdgeDriverLinkTimeoutException
- EdgeDriverLinkDeviceConfigException
- EdgeDriverLinkDeviceOfflineException
- EdgeDriverLinkOfflineException
- EdgeDriverLinkDeviceProductSecretException
---
#### from uiotedgedriverlinksdk.client
- **[SubDevice()](#subdevice)**
- SubDevice#**[set_product_sn()](#set_product_sn)**
- SubDevice#**[set_device_sn()](#set_device_sn)**
- SubDevice#**[set_product_secret()](#set_product_secret)**
- SubDevice#**[set_msg_callback()](#set_msg_callback)**
- SubDevice#**[set_rrpc_callback()](#set_rrpc_callback)**
- SubDevice#**[login()](#login)**
- SubDevice#**[logout()](#logout)**
- SubDevice#**[publish()](#publish)**
- SubDevice#**[registerDevice()](#registerDevice)**
---
#### from uiotedgedriverlinksdk.edge
- **[register_device()](#register)**
- **[set_on_topo_change_callback()](#set_on_topo_change_callback)**
- **[set_on_status_change_callback()](#set_on_status_change_callback)**
- **[get_topo()](#get_topo)**
- **[add_topo()](#add_topo)**
- **[delete_topo()](#delete_topo)**
---
#### from uiotedgedriverlinksdk.nats
- **[natsPublish()](#natsPublish)**
- **[natsSubscribe()](#natsSubscribe)**
---
- **[get_edge_online_status()](#get_edge_online_status)**
---
<a name="getLogger"></a>
### getLogger()
返回驱动内置 logger。
---
<a name="getConfig"></a>
### getConfig()
返回驱动相关配置。
---
<a name="Config"></a>
### Config()
基于当前驱动配置字符串构造新的 Config 对象。
---
<a name="getDeviceInfos"></a>
### Config. getDeviceInfos()
返回所有设备相关信息,返回 DeviceInfo`List`
DeviceInfo 包括如下信息:
- productSN `str `: 官网申请的 productKey。
- deviceSN `str `: 设备名
- config`dict `:设备自定义配置
---
<a name="getDriverInfo"></a>
### Config. getDriverInfo()
返回驱动相关信息,返回 DriverInfo`List`
---
<a name="subdevice"></a>
### SubDevice(product_sn,device_sn, on_msg_callback)
设备接入客户端类, 用户主要通过它上下线设备和主动上报消息
- product_sn`str`: 云端分配的 ProductSN
- device_sn`str`: 云端分配的 DeviceSN
- on_msg_callback`func(topic:str, msg:b'')`: 云端下发消息回调,消息类型 []byte, 例如:` def callbacl(topic:str, msg:b''): print(str(msg,'utf-8')`
---
<a name="set_product_sn"></a>
### SubDevice.set_product_sn(product_sn)
设置子设备的 productSN
- product_sn`str`: 云端分配的 ProductSN
---
<a name="set_device_sn"></a>
### SubDevice.set_device_sn(device_sn)
设备子设备的 DeviceSN
- device_sn`str`: 云端分配的 DeviceSN
---
<a name="set_product_secret"></a>
### SubDevice.set_product_secret(product_secret)
设置子设备的 Product Secret
- product_secret`str`: 云端分配的 Product Secret
---
<a name="set_product_secret"></a>
### SubDevice.set_product_secret(product_secret)
设置子设备的 Product Secret
- product_secret`str`: 云端分配的 Product Secret
---
<a name="set_msg_callback"></a>
### SubDevice.set_msg_callback(msg_callback)
设置子设备的接收消息的回调函数
- set_msg_callback`func`: 子设备收消息回调,例如:` def callbacl(topic:str, msg:b''): print(str(msg,'utf-8')`
---
<a name="set_rrpc_callback"></a>
### SubDevice.set_rrpc_callback(msg_callback)->bytes
设置子设备的接收 RRPC 的回调函数
- set_RRPC_callback`func`: 子设备收消息回调,例如:` def callback(topic:str, msg:b''): return b 'hello'`
---
<a name="login"></a>
### SubDevice.login(sync=False, timeout=5)
上报上线事件到 Link IoT Edge
- sync`bool`: 是否异步登陆
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
<a name="logout"></a>
### SubDevice.logout(sync=False, timeout=5)
上报下线事件到 Link IoT Edge
- sync`bool`: 是否异步登陆
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
<a name="publish"></a>
### SubDevice.publish(topic, payload)
上报消息到 Link IoT Edge。异步
- topic`str`: 上报消息到 Link IoT Edge 的 mqtt topic。
- payload`[]byte`: 上报消息到 Link IoT Edge 的消息内容
---
<a name="registerDevice"></a>
### SubDevice.registerDevice(timeout)
动态注册一个设备到 Link IoT Edge。同步
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
---
<a name="register"></a>
### register_device(product_sn, device_sn, product_secret, timeout=5)
上报动态注册到 Link IoT Edge。同步执行等待响应
- product_sn`str`: 云端分配的 ProductSN
- device_sn`str`: 自定义的 DeviceSN
- product_secret`str`: ProductSecret
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
<a name="set_on_topo_change_callback"></a>
### set_on_topo_change_callback(callback)
云端 topo 信息变化的下发消息的回调函数
- callback`func`: 云端下发消息回调,消息类型 {}, 例如: `def callback(msg): print(msg)`
---
<a name="set_on_status_change_callback"></a>
### set_on_status_change_callback(callback)
云端设备启用和禁用信息变化的下发消息的回调函数
- callback`func`: 云端下发消息回调,消息类型 {}, 例如: `def callback(msg): print(msg)`
---
<a name="get_topo"></a>
### get_topo(timeout=5)
上报 get topo 信息到 Link IoT Edge。同步执行等待响应
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
<a name="add_topo"></a>
### add_topo(product_sn, device_sn, timeout=5)
上报 add topo 信息到 Link IoT Edge
- product_sn`str`: 云端分配的 ProductSN
- device_sn`str`: 云端分配的 DeviceSN
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
<a name="delete_topo"></a>
### delete_topo(product_sn, device_sn, timeout=5)
上报 delete topo 信息到 Link IoT Edge
- product_sn`str`: 云端分配的 ProductSN
- device_sn`str`: 云端分配的 DeviceSN
- timeout`int`: 等待响应超时时间,单位 s(秒)
---
<a name="get_edge_online_status"></a>
### get_edge_online_status()
获取网关的在线状态,返回 True / False
---
<a name="natsPublish"></a>
### natsPublish(subject, payload)
通过 nats Publish 消息
- subject`str`: nats Subject
- payload`bytes`: nats 消息
---
<a name="natsSubscribe"></a>
### natsSubscribe(subject, queue, callback)
通过 nats 订阅 主题
- subject`str`: nats Subject
- queue`str`: nats 队列
- callback`func(msg)`: nats 消息回调, msg 为 nats 消息
---