This commit is contained in:
joy,zhou 2021-02-01 12:01:24 +08:00
parent ecd3d48c40
commit 6bf7291552
4 changed files with 29 additions and 13 deletions

View File

@ -34,6 +34,7 @@
* 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)**
@ -132,6 +133,13 @@ DeviceInfo包括如下信息
* 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)
设置子设备的接收RRPC的回调函数
* set_RRPC_callback`func`: 子设备收消息回调,例如:` def callbacl(topic:str, msg:b''): print(str(msg,'utf-8')`
---
<a name="login"></a>

View File

@ -2,10 +2,10 @@ import json
from iotedgedriverlinksdk import _deviceInfos, _driverInfo
from iotedgedriverlinksdk.edge import (add_connect_map, del_connect_map,
device_login_async, device_login_sync,
device_logout_async,
device_logout_sync, register_device,
send_message)
device_login_async, device_login_sync,
device_logout_async,
device_logout_sync, register_device,
send_message)
from iotedgedriverlinksdk.exception import (
EdgeDriverLinkDeviceConfigException, EdgeDriverLinkDeviceOfflineException,
EdgeDriverLinkDeviceProductSecretException)
@ -17,6 +17,7 @@ class SubDevice(object):
self.product_sn = product_sn
self.product_secret = ''
self.callback = on_msg_callback
self.rrpc = None
self.online = False
if self.product_sn != '' and self.device_sn != '':
self._identity = self.product_sn+'.'+self.device_sn
@ -37,6 +38,9 @@ class SubDevice(object):
def set_msg_callback(self, msg_callback):
self.callback = msg_callback
def set_rrpc_callback(self, msg_callback):
self.rrpc = msg_callback
def get_device_info(self):
return {
"productSN": self.product_sn,

View File

@ -1,3 +1,10 @@
from iotedgedriverlinksdk.nats import (_nat_publish_queue,
_nat_subscribe_queue, publish_nats_msg)
from iotedgedriverlinksdk.exception import (EdgeDriverLinkException,
EdgeDriverLinkOfflineException,
EdgeDriverLinkTimeoutException)
from iotedgedriverlinksdk import _driver_id, getLogger
from cachetools import TTLCache
import base64
import json
import queue
@ -5,15 +12,8 @@ import random
import string
import threading
import time
import re
from cachetools import TTLCache
from iotedgedriverlinksdk import _driver_id, getLogger
from iotedgedriverlinksdk.exception import (EdgeDriverLinkException,
EdgeDriverLinkOfflineException,
EdgeDriverLinkTimeoutException)
from iotedgedriverlinksdk.nats import (_nat_publish_queue,
_nat_subscribe_queue, publish_nats_msg)
_logger = getLogger()
_action_queue_map = {}
@ -396,6 +396,10 @@ def _on_message(message):
# _logger.debug("normal message payload: {}".format(str(msg, 'utf-8')))
if identify in _connect_map:
sub_dev = _connect_map[identify]
if isinstance(topic, str) and topic.startswith("/$system/") and topic.find("/rrpc/request/") > 0:
if sub_dev.rrpc:
sub_dev.rrpc(topic, msg)
if sub_dev.callback:
sub_dev.callback(topic, msg)
else:

View File

@ -7,7 +7,7 @@ if not (sys.version_info[0] == 3):
setup(
name='iotedge_driver_link_sdk',
version='0.0.1',
version='0.0.2.beta',
author='ucloud.cn',
url='https://pypi.org/project/iotedge_driver_link_sdk/',
author_email='joy.zhou@ucloud.cn',