"""Read-only local connection check. Python 3.10+; asyncua 2.0.1. Install in a virtual environment: python -m pip install asyncua==2.0.1 Run: python read_iqunet_local.py opc.tcp://GATEWAY:4840 Optional: add --sensor YOUR_SENSOR_MAC to read its boardTemperature. Use the endpoint and access policy approved for your installation. """ import argparse import asyncio from asyncua import Client, ua async def read(endpoint, sensor=None): async with Client(endpoint, timeout=10) as client: # Standard OPC UA ServerStatus.CurrentTime node. clock = await client.get_node('i=2258').read_data_value() print('Connected. Server status:', clock.StatusCode.name) print('Server UTC:', clock.Value.Value.isoformat()) if sensor: namespace = await client.get_namespace_index('http://www.iqunet.com') temperature = await client.nodes.objects.get_child([ ua.QualifiedName(sensor, namespace), ua.QualifiedName('boardTemperature', namespace), ]) value = await temperature.read_data_value() print('Temperature (deg C):', value.Value.Value) print('Status:', value.StatusCode.name) print('Source UTC:', value.SourceTimestamp) if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('endpoint', help='Approved local opc.tcp endpoint') parser.add_argument('--sensor', help='Sensor macId shown in Sensor Manager') args = parser.parse_args() try: asyncio.run(read(args.endpoint, args.sensor)) except (OSError, TimeoutError, ua.UaError, ValueError) as error: parser.exit(1, f'Read failed: {type(error).__name__}: {error}\n')