Skip to content

Getting started

Ralf Steinert edited this page Nov 2, 2026 · 1 revision

Install

Python 3.10 or newer:

pip install opcua-sim
opcua-sim --version
opcua-sim 0.1.0

Run a device

opcua-sim profiles                       # what is bundled
opcua-sim map drive                      # its variables, methods and alarms
opcua-sim serve --profile drive --name pump
opcua-sim: 1 device(s) on opc.tcp://127.0.0.1:4840, control on :4841
  pump  (drive)

Leave it running and use a second terminal.

Talk to it

opcua-sim has a small client built in. On the generic profiles pump.Speed is short for ns=2;s=pump.Speed:

opcua-sim browse
opcua-sim write pump.SpeedSetpoint 30
opcua-sim call pump.Start
opcua-sim read pump.Speed pump.DeviceHealth

Break it

opcua-sim inject pump trip code=4
opcua-sim read pump.State pump.FaultCode pump.DeviceHealth    # 3, 4 and 1: tripped, failure
opcua-sim call pump.Start                                     # refused: BadInvalidState
opcua-sim clear pump trip
opcua-sim call pump.Reset

clear removes the cause, Reset clears the latch. In a second terminal, opcua-sim watch --alarms prints the alarm events as they happen.

From your own code

Look up the namespace index by its URI. The number is not fixed:

import asyncio

from asyncua import Client, ua


async def main(url="opc.tcp://127.0.0.1:4840"):
    async with Client(url) as client:
        idx = await client.get_namespace_index("urn:steitec:opcua-sim")
        pump = client.get_node(ua.NodeId("pump.MethodSet", idx))
        await pump.call_method(ua.NodeId("pump.Start", idx))
        await asyncio.sleep(1)
        speed = await client.get_node(ua.NodeId("pump.Speed", idx)).read_value()
        print(f"{speed:.1f} Hz")


asyncio.run(main())

A bench of several devices

name: demo plant
devices:
  - {name: oven, profile: temperature-controller}
  - {name: pump, profile: drive, params: {ramp: 5.0}}
  - {name: tank_pressure, profile: pressure-transmitter, params: {process: 4.0}}
  - {name: meter, profile: energy-meter, serial_number: EM-0042}
opcua-sim serve --bench plant.yaml

Security, users and your own profiles are in the README.

Next: Testing in CI or Fault injection recipes.

Clone this wiki locally