33 lines
722 B
Python
33 lines
722 B
Python
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())
|
|
|