1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Added OPC-UA Connector features:

- disableSubscriptions - true will disable subscriptions and activates read values in nodes only on scanning/re-scanning.
 - subCheckPeriodInMillis - interval in milliseconds to check information in nodes from subscription.
This commit is contained in:
zbeacon
2020-02-26 11:45:51 +02:00
parent f2f67f4721
commit 7e466e8c56
4 changed files with 19 additions and 10 deletions

1
.gitignore vendored
View File

@@ -21,3 +21,4 @@ thingsboard_gateway/storage/data/
/logs/
__pycache__
/thingsboard_gateway/config/
/venv/

View File

@@ -8,4 +8,5 @@ pyserial python3-pyserial; PEP386
pyyaml python3-PyYAML; PEP386
pyrsistent python3-pyrsistent; PEP386
importlib python3-importlib; PEP386
jsonparh-rw python3-jsonpath-rw; PEP386
jsonparh-rw python3-jsonpath-rw; PEP386
regex python3-regex; PEP386

View File

@@ -2,10 +2,12 @@
"server": {
"name": "OPC-UA Default Server",
"url": "localhost:4840/freeopcua/server/",
"scanPeriodInMillis": 10000,
"timeoutInMillis": 5000,
"security": "Basic128Rsa15",
"scanPeriodInMillis": 5000,
"disableSubscriptions":false,
"subCheckPeriodInMillis": 100,
"showMap": false,
"security": "Basic128Rsa15",
"identity": {
"type": "anonymous"
},

View File

@@ -115,7 +115,10 @@ class OpcUaConnector(Thread, Connector):
log.info("OPC-UA connector %s connected to server %s", self.get_name(), self.__server_conf.get("url"))
self.__opcua_nodes["root"] = self.client.get_objects_node()
self.__opcua_nodes["objects"] = self.client.get_objects_node()
self.__sub = self.client.create_subscription(self.__server_conf.get("scanPeriodInMillis", 500), self.__sub_handler)
if not self.__server_conf.get("disableSubscriptions", False):
self.__sub = self.client.create_subscription(self.__server_conf.get("subCheckPeriodInMillis", 500), self.__sub_handler)
else:
self.__sub = False
self.__scan_nodes_from_config()
self.__previous_scan_time = time.time() * 1000
log.debug('Subscriptions: %s', self.subscribed)
@@ -127,10 +130,11 @@ class OpcUaConnector(Thread, Connector):
if not self.__connected and not self.__stopped:
self.client.connect()
elif not self.__stopped:
if time.time()*1000 - self.__previous_scan_time > self.__server_conf.get("scanPeriodInMillis", 60000):
if self.__server_conf.get("disableSubscriptions", False) and time.time()*1000 - self.__previous_scan_time > self.__server_conf.get("scanPeriodInMillis", 60000):
self.__scan_nodes_from_config()
self.__previous_scan_time = time.time() * 1000
elif self.data_to_send:
if self.data_to_send:
self.__gateway.send_to_storage(self.get_name(), self.data_to_send.pop())
if self.__stopped:
self.close()
@@ -285,9 +289,9 @@ class OpcUaConnector(Thread, Connector):
self.data_to_send.append(converted_data)
self.statistics['MessagesSent'] += 1
if self.__sub is None:
self.__sub = self.client.create_subscription(self.__server_conf.get("scanPeriodInMillis", 500),
self.__sub_handler)
self.__sub.subscribe_data_change(information_node)
self.__sub = self.client.create_subscription(self.__server_conf.get("subCheckPeriodInMillis", 500), self.__sub_handler)
if self.__sub:
self.__sub.subscribe_data_change(information_node)
log.debug("Added subscription to node: %s", str(information_node))
log.debug("Data to ThingsBoard: %s", converted_data)
else:
@@ -412,7 +416,8 @@ class OpcUaConnector(Thread, Connector):
if self.__show_map:
log.debug("SHOW MAP: Current node path: %s - NODE FOUND", new_node_path)
if new_node_class == ua.NodeClass.Object:
log.debug("Search in %s", new_node_path)
if self.__show_map:
log.debug("SHOW MAP: Search in %s", new_node_path)
self.__search_node(new_node, fullpath, result=result)
elif new_node_class == ua.NodeClass.Variable:
log.debug("Found in %s", new_node_path)