Python Forum
freeOpcUa - get value of subscription
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
freeOpcUa - get value of subscription
#1
Hi,

first of all I'm new in this forum and also new to python.

I've set up an OPC UA client in Pyhon by using the freeOpcUa library.

https://github.com/FreeOpcUa/python-opcua

The connection to my server works just fine. There is new data at the Server every 20 ms or so.
What I've tried so far is reading the nodes value in a for-loop by using the get_node() and get_value() functions.
Doing it this way, it takes a long time to read for example 1000 values of a variable.

So it tried to set up a subscription by using the SubHandler class. My code is shown below. I want to use a sampling interval of 10 ms.

The subscription works and I'm getting the notification if a value at the server changes. I'm getting the message "Python: New data change event" + the value. For logging purposes I'm only interested in the values. So I deleted the print message from the SubHandler-Class, but if the value change occurs I'm still getting the notification message.

I don't know how to save the changed values to an external variable, to prepare it for logging in a .csv-file.

Any help how to get rid of the notifications and access the values?

Thanks a lot.

Johna

from opcua import Client


class SubHandler(object):

    """
    Subscription Handler. To receive events from server for a subscription
    data_change and event methods are called directly from receiving thread.
    Do not do expensive, slow or network operation there. Create another 
    thread if you need to do such a thing
    """

    def datachange_notification(self, node, val, data):
     
       print("")

    def event_notification(self, event):
       print("")



client = Client("opc.tcp://xxx_yyy_zzz")

client.connect()


X    =   client.get_node("node_name1")
Y    =   client.get_node("node_name2")
Z    =   client.get_node("node_name3")

data = [X,Y,Z]

handler = SubHandler()
sub = client.create_subscription(10,handler)
handle = sub.subscribe_data_change(data)
Larz60+ likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: 'Subscription' object is not iterable in Python hfan6206 2 5,066 Apr-11-2018, 03:59 AM
Last Post: hfan6206
  Run on Flask blueprint/view like mqtt subscription service? nardev 0 2,940 Jan-25-2017, 07:02 PM
Last Post: nardev

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020