Created
January 22, 2020 19:13
-
-
Save ZuZuD/a65ece60c1b54003e9b2a7d5520ce091 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==== Server === | |
In [1]: from opcua import ua, server | |
...: | |
...: s = server.server.Server() | |
...: s.load_certificate("/etc/pki/tls/certs/mycert.pem") | |
...: s.load_private_key("/etc/pki/tls/certs/mykeykey.der") | |
...: | |
...: # allow Basic256Sha256_SignAndEncrypt | |
...: # s.get_endpoint() would return only that security policy | |
...: # and clients are restricted to it. | |
...: s.set_security_policy([ | |
...: ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt, | |
...: ua.SecurityPolicyType.NoSecurity, | |
...: ]) | |
...: | |
...: # get Objects node, this is where we should put our custom stuff | |
...: objects = s.get_objects_node() | |
...: print("I got objects folder: ", objects) | |
...: | |
...: # now adding some object to our addresse space | |
...: idx = s.register_namespace(uri) | |
...: myobject = objects.add_object(idx, "NewObject") | |
...: myvar = myobject.add_variable(idx, "MyVariable", [16, 56]) | |
...: myprop = myobject.add_property(idx, "myprop", 9.9) | |
...: myfolder = myobject.add_folder(idx, "myfolder") | |
...: s.start() | |
I got objects folder: Node(TwoByteNodeId(i=85)) | |
Creating an open endpoint to the server, although encrypted endpoints are enabled. | |
Listening on 0.0.0.0:4840 | |
Creating SecurityPolicy: <class 'opcua.ua.uaprotocol_hand.SecurityPolicy'> 1 None | |
Creating SecurityPolicy: <class 'opcua.ua.uaprotocol_hand.SecurityPolicy'> 1 None | |
Creating SecurityPolicy: <class 'opcua.ua.uaprotocol_hand.SecurityPolicy'> 1 None | |
Creating SecurityPolicy: <class 'opcua.ua.uaprotocol_hand.SecurityPolicy'> 1 None | |
==== Client ==== | |
In [1]: from opcua import ua | |
...: from opcua import client | |
...: | |
...: c = client.client.Client(url="opc.tcp://0.0.0.0:4840/freeopcua/server/") | |
...: | |
...: # connect calls create_session() | |
...: c.connect() | |
...: | |
...: # create a subcription and sub to a node created above | |
...: sub = c.create_subscription(1000,1) | |
...: sub.subscribe_data_change(c.get_node("ns=2;i=3")) | |
http://www.w3.org/2000/09/xmldsig#rsa-sha1 | |
Sending publish message | |
Sending publish message | |
Out[1]: 112 | |
DataChange subscription created but handler has no datachange_notification method | |
Sending publish message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment