tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_service.bash
author Edouard Tisserant <edouard.tisserant@gmail.com>
Thu, 02 Feb 2023 17:17:04 +0100
branchwxPython4
changeset 3720 d0a9c01ee7a5
parent 3718 7841b651d601
child 3820 46f3ca3f0157
permissions -rw-r--r--
Tests: IDE: explicitely wait for build success rather than just stdout to become silent.
#!/bin/bash

echo "Instant encrypted OPC-UA server for test"

yes "" | openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem \
        -days 355 -nodes -addext "subjectAltName = URI:urn:example.org:FreeOpcUa:python-opcua"
openssl x509 -outform der -in my_cert.pem -out my_cert.der

PROJECT_FILES_DIR=$BEREMIZPATH/tests/projects/opcua_browse_encrypted/project_files
mkdir $PROJECT_FILES_DIR
cp my_cert.der my_private_key.pem $PROJECT_FILES_DIR

echo "CERTS READY"

# Run server
exec $BEREMIZPYTHONPATH - << EOF

import sys
import os
import time

from opcua import ua, Server

server = Server()
host = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1")
endpoint = "opc.tcp://"+host+":4840/freeopcua/server/"
server.set_endpoint(endpoint)

server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt])
server.load_certificate("my_cert.der")
server.load_private_key("my_private_key.pem")

uri = "http://beremiz.github.io"
idx = server.register_namespace(uri)

objects = server.get_objects_node()

testobj = objects.add_object(idx, "TestObject")
testvarout = testobj.add_variable(idx, "TestOut", 1.2)
testvar = testobj.add_variable(idx, "TestIn", 5.6)
testvar.set_writable()

server.start()

try:
    while True:
        time.sleep(1)
        inval=testvar.get_value()
        print inval
        testvarout.set_value(inval*2)
        sys.stdout.flush()
finally:
    server.stop()
EOF