Go to the documentation of this file.00001 import sys
00002 sys.path.insert(0, "..")
00003 import time
00004 from datetime import datetime
00005
00006 from opcua import ua, Server
00007 from opcua.server.history_sql import HistorySQLite
00008
00009
00010 if __name__ == "__main__":
00011
00012
00013 server = Server()
00014 server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
00015
00016
00017 uri = "http://examples.freeopcua.github.io"
00018 idx = server.register_namespace(uri)
00019
00020
00021 objects = server.get_objects_node()
00022
00023
00024 myobj = objects.add_object(idx, "MyObject")
00025
00026
00027
00028 etype = server.create_custom_event_type(2, 'MyFirstEvent', ua.ObjectIds.BaseEventType,
00029 [('MyNumericProperty', ua.VariantType.Float),
00030 ('MyStringProperty', ua.VariantType.String)])
00031
00032 etype2 = server.create_custom_event_type(2, 'MySecondEvent', ua.ObjectIds.BaseEventType,
00033 [('MyOtherProperty', ua.VariantType.Float)])
00034
00035
00036 myevgen = server.get_event_generator(etype, myobj)
00037 myevgen.event.Severity = 500
00038 myevgen.event.MyStringProperty = ua.Variant("hello world")
00039 myevgen.event.MyNumericProperty = ua.Variant(-456)
00040
00041
00042 myevgen2 = server.get_event_generator(etype2, myobj)
00043 myevgen2.event.Severity = 123
00044 myevgen2.event.MyOtherProperty = ua.Variant(1.337)
00045
00046
00047 serverevgen = server.get_event_generator()
00048 serverevgen.event.Severity = 111
00049
00050
00051 server.iserver.history_manager.set_storage(HistorySQLite("my_event_history.sql"))
00052
00053
00054 server.start()
00055
00056
00057 server.iserver.enable_history_event(myobj, period=None)
00058
00059
00060 server_node = server.get_node(ua.ObjectIds.Server)
00061 server.historize_node_event(server_node, period=None)
00062
00063 try:
00064 count = 0
00065 while True:
00066 time.sleep(1)
00067 count += 0.1
00068
00069
00070 myevgen.trigger(message="This is MyFirstEvent " + str(count))
00071 myevgen2.trigger(message="This is MySecondEvent " + str(count))
00072 serverevgen.trigger(message="Server Event Message")
00073
00074
00075 end_time = datetime.utcnow()
00076 server_event_history = server_node.read_event_history(None, end_time, 0)
00077
00078 finally:
00079
00080 server.stop()