server-datavalue-history.py
Go to the documentation of this file.
1 import sys
2 sys.path.insert(0, "..")
3 import time
4 import math
5 
6 
7 from opcua import ua, Server
8 from opcua.server.history_sql import HistorySQLite
9 
10 
11 if __name__ == "__main__":
12 
13  # setup our server
14  server = Server()
15  server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
16 
17  # setup our own namespace, not really necessary but should as spec
18  uri = "http://examples.freeopcua.github.io"
19  idx = server.register_namespace(uri)
20 
21  # get Objects node, this is where we should put our custom stuff
22  objects = server.get_objects_node()
23 
24  # populating our address space
25  myobj = objects.add_object(idx, "MyObject")
26  myvar = myobj.add_variable(idx, "MyVariable", ua.Variant(0, ua.VariantType.Double))
27  myvar.set_writable() # Set MyVariable to be writable by clients
28 
29  # Configure server to use sqlite as history database (default is a simple memory dict)
30  server.iserver.history_manager.set_storage(HistorySQLite("my_datavalue_history.sql"))
31 
32  # starting!
33  server.start()
34 
35  # enable data change history for this particular node, must be called after start since it uses subscription
36  server.historize_node_data_change(myvar, period=None, count=100)
37 
38  try:
39  count = 0
40  while True:
41  time.sleep(1)
42  count += 0.1
43  myvar.set_value(math.sin(count))
44 
45  finally:
46  # close connection, remove subscriptions, etc
47  server.stop()


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Tue Jan 19 2021 03:12:44