Conditions | 3 |
Total Lines | 34 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import sys |
||
10 | async def main(): |
||
11 | |||
12 | # setup our server |
||
13 | server = Server() |
||
14 | await server.init() |
||
15 | server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/") |
||
16 | |||
17 | # load server certificate and private key. This enables endpoints |
||
18 | # with signing and encryption. |
||
19 | await server.load_certificate("certificate-example.der") |
||
20 | await server.load_private_key("private-key-example.pem") |
||
21 | |||
22 | # set all possible endpoint policies for clients to connect through |
||
23 | server.set_security_policy([ |
||
24 | ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt, |
||
25 | ua.SecurityPolicyType.Basic256Sha256_Sign, |
||
26 | ]) |
||
27 | |||
28 | # setup our own namespace, not really necessary but should as spec |
||
29 | uri = "http://examples.freeopcua.github.io" |
||
30 | idx = await server.register_namespace(uri) |
||
31 | |||
32 | # populating our address space |
||
33 | myobj = await server.nodes.objects.add_object(idx, "MyObject") |
||
34 | myvar = await myobj.add_variable(idx, "MyVariable", 6.7) |
||
35 | await myvar.set_writable() # Set MyVariable to be writable by clients |
||
36 | |||
37 | # starting! |
||
38 | async with server: |
||
39 | count = 0 |
||
40 | while True: |
||
41 | await asyncio.sleep(1) |
||
42 | count += 0.1 |
||
43 | await myvar.write_value(count) |
||
44 | |||
50 |