Skip to content

Commit

Permalink
Added OPC-UA Connector features:
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
imbeacon committed Feb 26, 2020
1 parent f2f67f4 commit 7e466e8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ thingsboard_gateway/storage/data/
/logs/
__pycache__
/thingsboard_gateway/config/
/venv/
3 changes: 2 additions & 1 deletion for_build/DEBIAN/pydist-overrides
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions thingsboard_gateway/config/opcua.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
19 changes: 12 additions & 7 deletions thingsboard_gateway/connectors/opcua/opcua_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def run(self):
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)
Expand All @@ -127,10 +130,11 @@ def run(self):
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()
Expand Down Expand Up @@ -285,9 +289,9 @@ def __search_nodes_and_subscribe(self, device_info):
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:
Expand Down Expand Up @@ -412,7 +416,8 @@ def __search_node(self, current_node, fullpath, search_method=False, result=[]):
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)
Expand Down

0 comments on commit 7e466e8

Please sign in to comment.