server-datavalue-history.py
Go to the documentation of this file.
00001 import sys
00002 sys.path.insert(0, "..")
00003 import time
00004 import math
00005 
00006 
00007 from opcua import ua, Server
00008 from opcua.server.history_sql import HistorySQLite
00009 
00010 
00011 if __name__ == "__main__":
00012 
00013     # setup our server
00014     server = Server()
00015     server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
00016 
00017     # setup our own namespace, not really necessary but should as spec
00018     uri = "http://examples.freeopcua.github.io"
00019     idx = server.register_namespace(uri)
00020 
00021     # get Objects node, this is where we should put our custom stuff
00022     objects = server.get_objects_node()
00023 
00024     # populating our address space
00025     myobj = objects.add_object(idx, "MyObject")
00026     myvar = myobj.add_variable(idx, "MyVariable", ua.Variant(0, ua.VariantType.Double))
00027     myvar.set_writable()  # Set MyVariable to be writable by clients
00028 
00029     # Configure server to use sqlite as history database (default is a simple memory dict)
00030     server.iserver.history_manager.set_storage(HistorySQLite("my_datavalue_history.sql"))
00031 
00032     # starting!
00033     server.start()
00034 
00035     # enable data change history for this particular node, must be called after start since it uses subscription
00036     server.historize_node_data_change(myvar, period=None, count=100)
00037 
00038     try:
00039         count = 0
00040         while True:
00041             time.sleep(1)
00042             count += 0.1
00043             myvar.set_value(math.sin(count))
00044 
00045     finally:
00046         # close connection, remove subscriptions, etc
00047         server.stop()


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Sat Jun 8 2019 18:26:23