From 10d2ab52688cf2b92e2bad828d14668dc43bb0f3 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 3 Mar 2022 13:17:54 +0100 Subject: [PATCH] subscription experiments --- snippets/test4.py | 32 ++++++++++++++++++++++++++++++++ src/config.json | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 snippets/test4.py diff --git a/snippets/test4.py b/snippets/test4.py new file mode 100644 index 0000000..ebdbfd5 --- /dev/null +++ b/snippets/test4.py @@ -0,0 +1,32 @@ +import asyncio +from asyncua import Client + + + +NODE_IDS = [ + 'ns=0;i=345', + 'ns=0;i=348', + 'ns=0;i=351', + 'ns=0;i=354' +] +URL = 'opc.tcp://172.16.3.60:4840' + + +class SubscriptionHandler: + def datachange_notification(self, node, val, data): + print(f"received: {node=}, {val=}, {data=}") + +async def test(): + client = Client(url=URL, timeout=10.0) + # await client.set_security_string('') + async with client: + subscription = await client.create_subscription(500, SubscriptionHandler()) + nodes = [ client.get_node(n) for n in NODE_IDS ] + await subscription.subscribe_data_change(nodes) + await asyncio.sleep(300) + await subscription.delete() + + + +asyncio.run(test()) + diff --git a/src/config.json b/src/config.json index 06ae2ff..e9d5540 100644 --- a/src/config.json +++ b/src/config.json @@ -11,7 +11,7 @@ "opcua": [ { "enabled": "true", - "type": "flat", + "type": "structured", "url": "opc.tcp://172.16.3.60:4840", "name": "apl", "period": 1.0,