Qt OPC-UA - Accessing Trend/Historical Data

1.3k Views Asked by At

I'm using Qt 5.11.1 with Qt OPC Ua and the Open62541 backend to create an OPC Client application.

Is it at all possible to make a request for historical data with the Qt OPC UA module? E.g. Get the values for this variable (node) between these two times.

My server application has this functionality (FreeOpcUa) as I can set variables to be 'historized' and view previously stored values. But I cannot see an obvious solution to access this data easily on the client side.

At the moment I'm considering exposing a function on my server for each variable which would take in a start and end timestamp and manually gather the values and format them into a string or some object for the client to use.

Would anyone have any ideas or thoughts on a better way to do this? I'm not overly familiar with OPC-UA or Qt so may just be missing something obvious.

2

There are 2 best solutions below

0
On BEST ANSWER

To use the OPC UA History Feature, both your OPC UA Client and Server shall supports the HistoryRead/HistoryWrite Services.

I don't know the status of the feature for your Server but for your Client (Open62541) those Services are not completely functionnal yet. Check the FEATURES document from their GitHub here

Apparently those should be fully functionnal within the next 0.4 Release.

0
On

The Freeopcua-Server supports historization (https://python-opcua.readthedocs.io/en/latest/server.html).

You have to enable historization per node (i.e. per variable you want to historize):

historize_node_data_change(node, period=datetime.timedelta(7), count=0)

Start historizing supplied nodes

Args:

node: node or list of nodes that can be historized (variables/properties)

period: time delta to store the history; older data will be deleted from the storage

count: number of changes to store in the history

e.g. if you want to serve the history of the temperature you have to use "server.historize_node_data_change(Temp, period=datetime.timedelta(7), count=0)" (after the server was started):

[Python]:

from opcua import Server
from random import randint
import datetime
import time

server = Server()

server.set_endpoint("opc.tcp://192.168.178.20:443")
addspace = server.register_namespace("OPCUA_BurkhardsTemperatureSensor")

node = server.get_objects_node()

Param = node.add_object(addspace, "Thermometer_1")

Temp = Param.add_variable(addspace, "Temperature", 0)
Temp.set_writable()

Time = Param.add_variable(addspace, "Time", 0)
Time.set_writable()

SerialNr = Param.add_variable(addspace, "SerialNr.", "2323784628346")

server.start()

server.historize_node_data_change(Temp, period=datetime.timedelta(7), count=0)

while True:
    Temperature = randint (10,50)
    TIME = datetime.datetime.now()
    
    print (Temperature,TIME)

    Temp.set_value(Temperature)
    Time.set_value(TIME)
    
    time.sleep (2)