Example #1
0
class HelloServer:
    def __init__(self, endpoint, name, model_filepath):
        self.server = Server()

        #  This need to be imported at the start or else it will overwrite the data
        self.server.import_xml(model_filepath)

        self.server.set_endpoint(endpoint)
        self.server.set_server_name(name)

        objects = self.server.get_objects_node()

        freeopcua_namespace = self.server.get_namespace_index(
            "urn:freeopcua:python:server")
        hellower = objects.get_child("0:Hellower")
        hellower_say_hello = hellower.get_child("0:SayHello")

        self.server.link_method(hellower_say_hello, say_hello_xml)

        hellower.add_method(freeopcua_namespace, "SayHello2", say_hello,
                            [ua.VariantType.Boolean], [ua.VariantType.String])

        hellower.add_method(freeopcua_namespace, "SayHelloArray",
                            say_hello_array, [ua.VariantType.Boolean],
                            [ua.VariantType.String])

    def __enter__(self):
        self.server.start()
        return self.server

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.server.stop()
Example #2
0
class HelloServer:
    def __init__(self, endpoint, name, model_filepath):
        self.server = Server()

        #  This need to be imported at the start or else it will overwrite the data
        self.server.import_xml(model_filepath)

        self.server.set_endpoint(endpoint)
        self.server.set_server_name(name)

        objects = self.server.get_objects_node()

        freeopcua_namespace = self.server.get_namespace_index("urn:freeopcua:python:server")
        hellower = objects.get_child("0:Hellower")
        hellower_say_hello = hellower.get_child("0:SayHello")

        self.server.link_method(hellower_say_hello, say_hello_xml)

        hellower.add_method(
            freeopcua_namespace, "SayHello2", say_hello, [ua.VariantType.Boolean], [ua.VariantType.String])

        hellower.add_method(
            freeopcua_namespace, "SayHelloArray", say_hello_array, [ua.VariantType.Boolean], [ua.VariantType.String])

    def __enter__(self):
        self.server.start()
        return self.server

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.server.stop()
Example #3
0
class MyDeviceServer(object):
    def __init__(self, endpoint, name):
        # Logging configuration
        self.logger = logging.getLogger('MyDeviceServer')
        self.logger.setLevel(logging.INFO)

        # Setup server
        self.server = Server()
        self.server.import_xml("MyDevice.xml")
        self.server.set_endpoint(endpoint)
        self.server.set_server_name(name)

        self.objects_node = self.server.get_objects_node()
        self.my_device_node = self.objects_node.get_child("0:MyDevice")
        self.my_device_toggle_b = self.my_device_node.get_child("0:ToggleB")
        self.my_device_toggle_c = self.my_device_node.get_child("0:ToggleC")
        self.my_device_toggle_d = self.my_device_node.get_child("0:ToggleD")

        self.server.link_method(self.my_device_toggle_b, self.toggle_b)
        self.server.link_method(self.my_device_toggle_c, self.toggle_c)
        self.server.link_method(self.my_device_toggle_d, self.toggle_d)

        self.my_variable_a = self.my_device_node.get_child("0:VariableA")
        self.my_variable_b = self.my_device_node.get_child("0:VariableB")
        self.my_variable_c = self.my_device_node.get_child("0:VariableC")
        self.my_variable_d = self.my_device_node.get_child("0:VariableD")
        self.my_variable_e = self.my_device_node.get_child("0:VariableE")

    @uamethod
    def toggle_b(self, parent):
        self.logger.info("Call Toggle B method")
        self.my_variable_b.set_value(not self.my_variable_b.get_value())

    @uamethod
    def toggle_c(self, parent):
        self.logger.info("Call Toggle C method")
        self.my_variable_c.set_value(not self.my_variable_c.get_value())

    @uamethod
    def toggle_d(self, parent):
        self.logger.info("Call Toggle D method")
        self.my_variable_d.set_value(not self.my_variable_d.get_value())

    def start(self):
        self.server.start()

    def stop(self):
        self.server.stop()

    def setVarA(self, intNumber):
        self.my_variable_a.set_value(intNumber)

    def setVarE(self, intNumber):
        self.my_variable_e.set_value(intNumber)
class HelloServer:
    def __init__(self, endpoint, name, model_filepath):
        self.server = Server()

        #  This need to be imported at the start or else it will overwrite the data
        self.server.import_xml(model_filepath)

        self.server.set_endpoint(endpoint)
        self.server.set_server_name(name)

        objects = self.server.get_objects_node()
	
	ESP8266=self.server.get_node("ns=0;i=20005")
	print("ESP8266: ")
	print(ESP8266)	

	#death_button=ESP8266.get_children()
	watering_status=ESP8266.get_value()
	print(watering_status)
	switch_method=self.server.get_node("ns=0;i=20006")
        freeopcua_namespace = self.server.get_namespace_index("urn:freeopcua:python:server")
#        hellower = objects.get_child("0:Hellower")
#        hellower_say_hello = hellower.get_child("0:SayHello")
	self.server.link_method(switch_method, switch_mtd)
#        self.server.link_method(hellower_say_hello, say_hello_xml)

#        hellower.add_method(
#            freeopcua_namespace, "SayHello2", say_hello, [ua.VariantType.Boolean], [ua.VariantType.String])

#        hellower.add_method(
#            freeopcua_namespace, "SayHelloArray", say_hello_array, [ua.VariantType.Boolean], [ua.VariantType.String])

    def __enter__(self):
        self.server.start()
        return self.server

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.server.stop()
Example #5
0
    server.set_server_name("Proyecto Industria 4.0")
    # load server certificate and private key. This enables endpoints
    # with signing and encryption.
    # server.load_certificate("certificate-example.der")
    # server.load_private_key("private-key-example.pem")

    ns = server.get_namespace_array()
    uax = str(ns.index("http://opcfoundation.org/UA/"))
    dix = str(ns.index("http://opcfoundation.org/UA/DI/"))
    fdix = str(ns.index("http://fdi-cooperation.com/OPCUA/FDI5/"))
    i4ox = str(ns.index("http://juandavid.univalle/i4o/"))
    m1x = str(ns.index("http://juandavid.univalle/i4o/Mixer1/"))
    m2x = str(ns.index("http://juandavid.univalle/i4o/Mixer2/"))

    server.link_method(
        server.get_node("ns=" + i4ox + ";s=D.ST.O.AS.InvokeAction"),
        Methods.execute)
    server.link_method(
        server.get_node("ns=" + m1x + ";s=D.Mx1.O.AS.InvokeAction"),
        Methods.execute)
    server.link_method(
        server.get_node("ns=" + m2x + ";s=D.Mx2.O.AS.InvokeAction"),
        Methods.execute)

    Modules.ns_printer(ns)

    # Server conf for using sqlite for history
    # server.iserver.history_manager.set_storage(HistorySQLite("my_datavalue_history.sql"))

    # starting!
    server.start()