Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create client-for-historian-nodes.py #1502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions examples/client-for-historian-nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import datetime
import sys
from opcua import Client, ua


# Connect to the OPC server
url = "opc.tcp://localhost:4840"
client = Client(url)
client.connect()

# Define the tags to fetch
tags = ["ns=2;i=2"]

# Define the start and end time for the historical data
end_time = datetime.datetime.utcnow()
start_time = end_time - datetime.timedelta(hours=1)


try:
# Fetch the historian data
historian_data = []
for tag in tags:
node = client.get_node(tag)
data = node.read_raw_history(start_time, end_time, numvalues=0)
historian_data.append((tag, data))

# Print the data
for tag, values in historian_data:
print(tag)
for value in values:
print(value)


except Exception as e:
print(e)
sys.exit()

finally:
# Disconnect from the OPC server
client.disconnect()