0
votes

I currently stuck at a DataValue (wrong SourceTimestamp) problem.

my OPCUA Server (programmed in python) has a variable with the following DataValue:

DataValue(Value:Variant(val:36,type:VariantType.Int64), StatusCode:StatusCode(Good), SourceTimestamp:2021-06-04 14:22:47.425125)

In my client, the SourceTimestamp is 2 hours earlier (due to timezones) and there is None server Timestamp.

How can I change the SourceTimestamp? I figured that I need to do it with

.set_data_value()

However, I don“t get the syntax behind it. What does self mean?

def set_value(self, value, varianttype=None):

Also, how can I show the ServerTimestamp?

All tips are appreciated!

1

1 Answers

0
votes

The set_value API doesn't support setting timestamps directly (at least AFAIK). The solution is passing an instance of opcua.ua.DataValue instead of the "real" value.

This means, instead of something like this:

node.set_value(42)

You pass an instance of DataValue with the desired timestamp. I.e. something along these lines:

# Just an example. Use the time that makes sense for you
timestamp = datetime.datetime.now()  

# NOTE: here you can pass 'serverTimestamp' as well.
datavalue = ua.DataValue(variant=42, sourceTimestamp=timestamp)
node.set_value(datavalue)