server-with-encryption.py
Go to the documentation of this file.
1 import sys
2 import time
3 
4 sys.path.insert(0, "..")
5 
6 from opcua import ua, Server
7 
8 
9 if __name__ == "__main__":
10 
11  # setup our server
12  server = Server()
13  server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
14 
15  # load server certificate and private key. This enables endpoints
16  # with signing and encryption.
17  server.load_certificate("certificate-example.der")
18  server.load_private_key("private-key-example.pem")
19 
20  # setup our own namespace, not really necessary but should as spec
21  uri = "http://examples.freeopcua.github.io"
22  idx = server.register_namespace(uri)
23 
24  # get Objects node, this is where we should put our custom stuff
25  objects = server.get_objects_node()
26 
27  # populating our address space
28  myobj = objects.add_object(idx, "MyObject")
29  myvar = myobj.add_variable(idx, "MyVariable", 6.7)
30  myvar.set_writable() # Set MyVariable to be writable by clients
31 
32  # starting!
33  server.start()
34  try:
35  count = 0
36  while True:
37  time.sleep(1)
38  count += 0.1
39  myvar.set_value(count)
40  finally:
41  #close connection, remove subcsriptions, etc
42  server.stop()


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