---
title: Example: OPC
slug: sdk/example-usages/opc
docTags: 
createdAt: 2025-03-20T19:52:22.970Z
---

End-to-end walkthrough: configure the Litmus Edge OPC UA server hierarchy, set security, add a user, and import existing DeviceHub tags.

## Setup

```python
from litmussdk import opc
```

The Litmus Edge OPC UA server can publish DeviceHub tags as OPC UA nodes for upstream OPC clients (SCADA, historians, etc.).

## 1. Inspect Current Hierarchy

```python
root = opc.get_root_node()
top_level = opc.get_node_by_paths([])    # children of root
```

## 2. Reset to a Clean State

:::BlockQuote
Use with caution; clears the hierarchy.
:::

```python
opc.reset_all_hierarchy()
```

## 3. Build a Hierarchy

```python
plant_node = opc.add_node_folder(parent_id=root.id, name="Plant1")
line1 = opc.add_node_folder(parent_id=plant_node.id, name="Line1")
pump = opc.add_node_device(parent_id=line1.id, name="Pump-01", device_id=device_id)
```

## 4. Import All Tags from a DeviceHub Device

```python
opc.import_all_dh_tags(device_id=device_id, parent_node_id=pump.id)
```

## 5. Add a Specific Tag

```python
opc.add_node_tag(
    parent_id=pump.id,
    tag_id=pressure_tag_id,
    name="Pressure",
)
```

## 6. Add a Logic Node (Computed)

```python
opc.add_node_logic(
    parent_id=pump.id,
    name="EfficiencyEstimate",
    formula="Pressure * FlowRate / 1000",
)
```

## 7. Update Security and Auth

```python
current = opc.get_security_and_auth_settings()

opc.change_security_and_auth_settings(
    security_modes=["SignAndEncrypt"],
    security_policies=["Basic256Sha256"],
    user_token_types=["UserName"],
)
```

## 8. Service Configuration

```python
config = opc.get_service_config()

opc.change_service_config(
    port=4840,
    application_name="LitmusEdge-OPC-UA",
    enable_anonymous=False,
)

# Restart the OPC UA service to apply
opc.start_stop_opc(action="restart")
```

## 9. Server Certificates and Metrics

```python
certs = opc.get_server_certificates()
metrics = opc.get_server_metrics()
```

## 10. Export the Hierarchy as JSON

Useful for snapshotting or for the [Air gap Features](docId\:dmvQ8b6h_Macksn07230r) builder.

```python
hierarchy_json = opc.export_as_json()

# Re-import on another Edge:
opc.import_json(hierarchy_json)
```

## See Also

- [Air gap Features](docId\:dmvQ8b6h_Macksn07230r) - including OPC config in deployment templates
