Example: OPC
12 min
End-to-end walkthrough: configure the Litmus Edge OPC UA server hierarchy, set security, add a user, and import existing DeviceHub tags.
Setup
from litmussdk import opcThe Litmus Edge OPC UA server can publish DeviceHub tags as OPC UA nodes for upstream OPC clients (SCADA, historians, etc.).
1. Inspect Current Hierarchy
root = opc.get_root_node()
top_level = opc.get_node_by_paths([]) # children of root2. Reset to a Clean State
Use with caution; clears the hierarchy.
opc.reset_all_hierarchy()3. Build a Hierarchy
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
opc.import_all_dh_tags(device_id=device_id, parent_node_id=pump.id)5. Add a Specific Tag
opc.add_node_tag(
parent_id=pump.id,
tag_id=pressure_tag_id,
name="Pressure",
)6. Add a Logic Node (Computed)
opc.add_node_logic(
parent_id=pump.id,
name="EfficiencyEstimate",
formula="Pressure * FlowRate / 1000",
)7. Update Security and Auth
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
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
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 builder.
hierarchy_json = opc.export_as_json()
# Re-import on another Edge:
opc.import_json(hierarchy_json)See Also
- Air gap Features - including OPC config in deployment templates