edouard@3543: #!/bin/bash edouard@3543: edouard@3672: echo "Instant OPC-UA server for test" edouard@3543: edouard@3549: # Run server edouard@3672: exec $BEREMIZPYTHONPATH - << EOF edouard@3543: edouard@3549: import sys edouard@3718: import os edouard@3549: import time edouard@3820: import asyncio edouard@3549: edouard@3820: from asyncua import Server edouard@3549: edouard@3820: async def main(): edouard@3820: server = Server() edouard@3820: host = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1") edouard@3820: endpoint = "opc.tcp://"+host+":4840/freeopcua/server/" edouard@3820: await server.init() edouard@3820: server.set_endpoint(endpoint) edouard@3549: edouard@3820: uri = "http://beremiz.github.io" edouard@3820: idx = await server.register_namespace(uri) edouard@3549: edouard@3820: objects = server.get_objects_node() edouard@3549: edouard@3820: testobj = await objects.add_object(idx, "TestObject") edouard@3820: testvarout = await testobj.add_variable(idx, "TestOut", 1.2) edouard@3820: testvar = await testobj.add_variable(idx, "TestIn", 5.6) edouard@3820: await testvar.set_writable() edouard@3549: edouard@3820: await server.start() edouard@3820: try: edouard@3820: while True: edouard@3820: await asyncio.sleep(1) edouard@3820: inval = await testvar.get_value() edouard@3820: print(inval) edouard@3820: await testvarout.set_value(inval*2) edouard@3820: sys.stdout.flush() edouard@3820: finally: edouard@3820: await server.stop() edouard@3549: edouard@3820: asyncio.run(main()) edouard@3820: edouard@3549: EOF