Skip to content

Python sample of subscribing data change using asyncua

Notifications You must be signed in to change notification settings

iwstkhr/opcua-subscription-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

OPC UA Subscription Sample

Python sample of subscribing data change using asyncua

Requirements

Only asyncua library is needed. Install it by the following command.

$ pip install asyncua

Usage

First, start an OPC UA testing server which writes a random int value to a variable node every second. The following sample Python script starts the testing server with opc.tcp://localhost:4840, having a variable node MyObject/MyVariable.

$ python server.py
Server started: OPC UA Server(opc.tcp://localhost:4840)

Then, run an OPC UA client script which reacts to data change notifications from the above OPC UA server. You can define an event handler datachange_notification in a class and pass it to create_subscription function.

$ python client.py
Data change notification was received and queued.
New value 4 of "['0:Root', '0:Objects', '2:MyObject', '2:MyVariable']" was processed.
Data change notification was received and queued.
New value 79 of "['0:Root', '0:Objects', '2:MyObject', '2:MyVariable']" was processed.
Data change notification was received and queued.
New value 75 of "['0:Root', '0:Objects', '2:MyObject', '2:MyVariable']" was processed.
...

About

Python sample of subscribing data change using asyncua

Topics

Resources

Stars

Watchers

Forks

Languages