Commit b5f7f864 authored by oroulet's avatar oroulet Committed by oroulet

use async with in example client with encryption

parent edd109ac
......@@ -15,24 +15,19 @@ private_key = f"certificates/peer-private-key-example-{cert_idx}.pem"
async def task(loop):
url = "opc.tcp://0.0.0.0:4840/freeopcua/server/"
try:
client = Client(url=url)
await client.set_security(
SecurityPolicyBasic256Sha256,
certificate_path=cert,
private_key_path=private_key,
server_certificate_path="certificate-example.der"
)
await client.connect()
client = Client(url=url)
await client.set_security(
SecurityPolicyBasic256Sha256,
certificate_path=cert,
private_key_path=private_key,
server_certificate_path="certificate-example.der"
)
async with client:
objects = client.nodes.objects
child = await objects.get_child(['0:MyObject', '0:MyVariable'])
print(await child.get_value())
await child.set_value(42)
print(await child.get_value())
except Exception:
_logger.exception('error')
finally:
await client.disconnect()
def main():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment