OPC UA Protocol Explained: Information Model, Client/Server, PubSub and Security

OPC UA names industrial data and can secure it. MQTT Sparkplug B carries report-by-exception to a broker. Many plants use both, with a gateway between them.

Standard

IEC 62541

Client/server

TCP 4840

IANA TLS name

4843 opcua-tls

PubSub

UDP or MQTT

What is OPC UA

OPC UA is a platform-independent way for industrial software to exchange data that already has a type and a name. The OPC Foundation publishes the specification, and IEC 62541 is that same body of work as an international standard. A server exposes an address space of typed nodes. A client connects, usually with the binary mapping opc.tcp on TCP port 4840, then browses, reads, writes, calls methods, or subscribes to changes.

That session is what most SCADA, MES, and historian projects mean by OPC UA. A second pattern, PubSub, publishes updates over UDP or MQTT without a session for every subscriber. Both patterns share the information model. They differ in who opens the connection.

On an IIoT project one person often wants OPC UA beside the machines, and someone else wants MQTT with Eclipse Sparkplug B toward a broker. OPC UA is the model and the commands. Sparkplug is report-by-exception through the broker. Plants often run both, with a gateway between the OPC UA server and the broker.

Classic OPC Data Access was Windows COM and DCOM. OPC UA replaced that architecture with its own services and encodings. If the open question is cyclic I/O inside a Siemens or Rockwell cell, start with the PROFINET vs EtherNet/IP vs Modbus TCP comparison. OPC UA usually sits above that choice.

How OPC UA works

Address space and nodes

Every item a client can touch is a node. It has a NodeId, a node class, a browse name, and a display name. A string NodeId looks like ns=2;s=Line1.Motor3.Speed. The number is the namespace index on that server. s means string and i= means numeric. Namespace 0 is the OPC UA specification. Other indexes belong to that server only.

Objects are things you browse, such as a line or a motor. Variables hold typed values. Methods are calls such as Start. Type nodes define those instances. Organizes, HasComponent, and HasProperty build the tree, and HasTypeDefinition points at the type. Browse walks those links. A read returns a DataValue: the value, a status code (Good, Uncertain, or Bad), a source timestamp, and a server timestamp. Engineering units are property nodes when the server provides them. Companion specifications define shared types, and they apply only when that server implements them. The diagram uses example names.

OPC UA address spaceAddress space: nodes and referencesExample browse names. HasComponent builds the tree.ObjectsFolderLine1ObjectMotor3ObjectSpeedVariable, DoubleRunningVariable, BooleanStartMethodTypesObjectType, DataTypeViewsOptional entry pointsjustprotocols.com
Objects group equipment, variables carry typed values, and methods are calls such as Start. Types and Views are the other standard entry points.

Client/server sessions and subscriptions

The client opens TCP to the endpoint, usually opc.tcp://hostname:4840, then builds a secure channel and a session:

  1. GetEndpoints returns URLs, security policies, and the server certificate.
  2. OpenSecureChannel sets MessageSecurityMode to None, Sign, or SignAndEncrypt on that endpoint port. Port 4843 is a separate registration, covered below.
  3. CreateSession starts the session. ActivateSession presents anonymous, a username, or a certificate. The application and the user are separate checks.
  4. Browse, Read, Write, and Call use NodeIds. Call runs a method. A rejected call returns a status code.
  5. CreateSubscription requests a publishing interval the server may revise. CreateMonitoredItems watches nodes, with an optional deadband.
  6. Outstanding Publish requests return a NotificationMessage on change, or a keep-alive when nothing changed.
  7. CloseSession and CloseSecureChannel finish.

A quiet session ends after the negotiated timeout. The server revises the publishing interval the client requested, so this guide states no default millisecond value. A Read is one round trip. A subscription asks for the next change, or a keep-alive if nothing changed.

OPC UA session and subscriptionSession, then subscriptionopc.tcp on port 4840 is the usual transportClientServerGetEndpointsPolicies and server certificateOpenSecureChannelNone, Sign, or SignAndEncryptCreateSessionThen ActivateSession with the userCreateSubscriptionMonitored items on NodeIdsPublishClient keeps a request outstandingNotificationMessageData change, or a keep-alivejustprotocols.com
The client opens a secure channel and a session, then subscribes. Later Publish responses carry a data change or a keep-alive. Timing on the diagram is only the order of calls.

PubSub

PubSub is OPC 10000-14. A publisher sends a NetworkMessage that holds one or more DataSet messages. Subscribers consume them. There is no CreateSession on that path, and no Publish request waiting on each listener.

UDP, including multicast, carries UADP, the UA datagram protocol. IANA registers UDP 4840 as opcua-udp, the OPC UA Multicast Datagram Protocol. The MQTT transport publishes UADP or JSON on a topic from that publisher's settings. That topic is not required to be Sparkplug. Use a session to browse, write, or call methods. Use PubSub when many listeners need the same dataset.

Transports and ports

The endpoint URL names the mapping, the host, and the port. These are the identifiers to put on a firewall request.

MappingPortWhat it is
opc.tcpTCP 4840Binary client/server. IANA opcua-tcp, "OPC UA Connection Protocol". Sign and SignAndEncrypt stay on this port.
opcua-udpUDP 4840IANA opcua-udp, "OPC UA Multicast Datagram Protocol", for PubSub.
opcua-tlsTCP and UDP 4843IANA opcua-tls, "OPC UA TCP Protocol over TLS/SSL".
HTTPS and WebSocketThe port in the URLOPC 10000-6 maps OPC UA to HTTPS and WebSockets. opc.wss is a common scheme. HTTPS uses 443 when that URL says so.

Sign and SignAndEncrypt stay on the endpoint port, usually 4840. Port 4843 is the IANA name for OPC UA TCP over TLS. Read GetEndpoints before opening it. A server that only listens on 4840 stays silent on 4843.

HTTPS and WebSocket endpoints use TLS the way HTTPS does. A WebSocket mapping starts with the HTTP upgrade in the WebSocket guide, then carries OPC UA messages. The common ports cheat sheet lists 4840 and 4843 beside Modbus TCP 502 and the EtherNet/IP ports.

Security

Each application instance, client or server, has an X.509 certificate. During OpenSecureChannel the peer checks it against a trust list or a certificate authority. The client also checks that the certificate is the server it meant to reach. A self-signed certificate is trusted only after someone places it on that list.

MessageSecurityMode has three values. None applies no OPC UA signature and no OPC UA encryption. Lab benches use it. A plant server that other networks can reach should leave it off. Sign lets the receiver detect tampering, and the application certificate authenticates the sender. SignAndEncrypt also encrypts the message body.

A SecurityPolicy names the algorithms. Current policies include Basic256Sha256, Aes128_Sha256_RsaOaep, and Aes256_Sha256_RsaPss. Basic128Rsa15 and Basic256 are deprecated. GetEndpoints lists what that server offers. ActivateSession then checks the user: anonymous, a username token, an X.509 user certificate, or an issued token. The application certificate identifies the software. The user token identifies the operator. OPC 10000-12 defines a Global Discovery Server for distributing certificates. Smaller systems copy trust lists by hand.

OPC UA vs classic OPC DA

Classic OPC Data Access, HDA, and Alarms and Events (A&E) are Windows COM and DCOM interfaces. DCOM is not one registered TCP port. OPC UA keeps named industrial data, drops DCOM, and can hold current values, history, and conditions in one address space. A wrapper can present old DA items as UA nodes. The client still opens a UA session.

Classic OPC DAOPC UA
PlatformWindows, COM and DCOMPlatform independent. IEC 62541.
TransportDCOM, with no single IANA portopc.tcp on 4840, plus HTTPS, WebSocket, and PubSub
DataItems in groups, with qualityTyped nodes, references, status codes, timestamps
SecurityDCOM security settingsX.509 application certificates, None, Sign, or SignAndEncrypt
MigrationLeave the DA server in placeA wrapper exposes those items as UA nodes

OPC UA vs MQTT Sparkplug B

MQTT moves messages through a broker. It defines QoS, retained messages, and the Last Will. It does not define an industrial payload, and it does not define the topic path for a motor speed. Two publishers can both be on MQTT and still be unreadable to each other.

Eclipse Sparkplug fills that gap. Sparkplug B is the payload and topic namespace to use. The namespace is spBv1.0 and the payload is protobuf. Sparkplug A (spAv1.0) is the older payload. The Sparkplug 3.0 specification deprecates it. The required topic form is namespace/group_id/message_type/edge_node_id/[device_id].

Example Sparkplug B topic

spBv1.0/Plant1/DDATA/Line1Gateway/Motor3

Example ids only. The fields are namespace, group, message type, edge node, and device. Node-level messages omit the device id.

Message types are NBIRTH, NDEATH, DBIRTH, DDEATH, NDATA, DDATA, NCMD, DCMD, and STATE. Birth certificates do, in one publish, the job Browse does in a session. NBIRTH lists the edge node's metrics. DBIRTH lists a device's metrics. After birth, DDATA or NDATA carries the metrics that changed. The specification allows a periodic report and treats report by exception as the normal mode.

NDEATH is the edge node death certificate, registered as the MQTT Will so the broker publishes it if the session dies. The payload carries bdSeq so a host can match that death to the birth. STATE is the host application online or offline message. NCMD and DCMD are commands through the broker, which the edge node maps onto the device. Sparkplug adds a shared topic, a shared payload, birth, and death. The browsable address space stays on the OPC UA server. This guide does not recommend a broker product.

Use OPC UA and Sparkplug togetherUse both: machine model, then brokerThe gateway translates. The protocols are not the same payload.Cell I/OPROFINET, EtherNet/IP,or ModbusOPC UA serverTyped nodesTCP 4840Edge gatewayOPC UA clientSparkplug edge nodeMQTT brokerSparkplug BspBv1.0 topicsSubscribersSCADA, MES,or a cloud appExample device topic: spBv1.0/Plant1/DDATA/Line1Gateway/Motor3justprotocols.com
I/O stays in the cell. OPC UA names the values. The gateway publishes Sparkplug B through the broker. The topic shows the Sparkplug shape with example ids.
OPC UA client/serverMQTT Sparkplug B
SpecificationOPC Foundation, IEC 62541Eclipse Sparkplug, carried on MQTT
ModelAddress space of typed nodesMetrics declared in a birth certificate
ConnectionSession to the server, usually TCP 4840MQTT session to a broker, commonly 1883 or 8883 for TLS
Learning the pointsBrowse referencesNBIRTH and DBIRTH
UpdatesSubscription inside the session, or ReadDDATA and NDATA, report by exception
CommandsWrite and CallNCMD and DCMD through the broker
Peer disappearedSession timeout, status on the next callNDEATH published from the MQTT Will
Strong fitRich model and commands near the machineEdge-to-cloud fan-out through a broker

Use OPC UA client/server beside the machine for browse, typed values, writes, and method calls, usually on port 4840 with Sign or SignAndEncrypt. Use MQTT Sparkplug B from the edge when subscribers already live on a broker and you want birth certificates plus report-by-exception.

Use both when the cell has an OPC UA server and the enterprise app speaks Sparkplug. The gateway reads or subscribes on 4840 and publishes spBv1.0 topics. Cyclic I/O stays on PROFINET, EtherNet/IP, or a Modbus TCP poll. OPC UA PubSub over MQTT carries a UA dataset, JSON or UADP. Choose Sparkplug when the hosts expect NBIRTH and NDEATH, and UA PubSub when the subscribers are UA subscribers.

OPC UA vs Modbus and fieldbus

Modbus TCP polls registers and coils on TCP port 502. The meaning of each number lives in a vendor map. The register addressing guide covers the gap between 40001 and offset 0.

An OPC UA variable has a name, a data type, a status code, and timestamps. A client can subscribe, call a method, and require SignAndEncrypt with an application certificate. Base Modbus TCP has none of those services. The usual plant puts Modbus below and OPC UA above. A meter speaks Modbus. A PLC or gateway polls it and exposes OPC UA nodes. Someone still binds the register to the node once. After that, other clients share the node.

Modbus TCPOPC UA
AddressRegister or coil numberNodeId and browse name
MeaningVendor register mapData type, and properties when the server has them
PatternClient poll on TCP 502Read, Write, Call, or a subscription
SecurityNone in the base protocolApplication certificates and a security mode
Typical placeDevice, or a simple supervisory pollSupervisory model above the device

Cyclic I/O stays on PROFINET or EtherNet/IP. Modbus TCP is enough when the job is only a poll. OPC UA does not define those I/O frames and does not replace a GSDML or an EDS. Keep the conveyor Run bit on the I/O protocol, and use OPC UA for supervisory values, recipes, and method calls. The three-protocol comparison says the same thing from the I/O side. A register-to-node gateway is useful, and the model is only as rich as the types that server implements.

Use cases

  • SCADA and HMI.Subscribe to process values on the controller's OPC UA server, and show status codes that are not Good, instead of polling a private register list.
  • MES. Call a method or write a recipe node when a work order starts. Arguments are typed. A rejected call returns a status code.
  • Historians. Store the source timestamp and the status code with the value, so a Bad sample is not recorded as a real zero.
  • Mixed lines. One cell can run PROFINET and another EtherNet/IP, and both controllers can still expose OPC UA to the same supervisory client.
  • Edge to cloud. The gateway in the diagram speaks OPC UA in the plant and Sparkplug B beyond the broker.
  • Classic DA. A UA wrapper exposes old Data Access items to clients that no longer open DCOM.

Facts you can check

Ports and the topic shape come from the registries and specifications named below. This page states no cycle time and no vendor benchmark.

Statement on this pageWhere to check it
OPC UA is the OPC Foundation specification and IEC 62541opcfoundation.org. IEC 62541 adopts that specification.
TCP 4840 is opcua-tcp and UDP 4840 is opcua-udpIANA names opcua-tcp and opcua-udp, assignee OPC Foundation. See the IANA service name registry.
TCP and UDP 4843 are opcua-tlsIANA service name opcua-tls, "OPC UA TCP Protocol over TLS/SSL", assignee OPC Foundation.
Sparkplug B uses spBv1.0 and birth, death, data, and command typesEclipse Sparkplug specification. Topic form namespace/group_id/message_type/edge_node_id/[device_id], with NBIRTH, NDEATH, DBIRTH, DDEATH, NDATA, DDATA, NCMD, DCMD, and STATE.

Frequently Asked Questions

What is OPC UA?

OPC UA is the IEC 62541 specification for platform-independent industrial data with meaning attached. A server exposes typed nodes. A client connects, usually with opc.tcp on port 4840, then browses, reads, writes, calls methods, or subscribes. PubSub can publish over UDP or MQTT. Security uses X.509 application certificates and None, Sign, or SignAndEncrypt. The OPC Foundation publishes the specification.

Should I use OPC UA or MQTT Sparkplug for IIoT?

Use OPC UA for the rich model and for commands near the machines. Use MQTT with Sparkplug B for report-by-exception from the edge through a broker. Sparkplug adds the spBv1.0 topic namespace, a protobuf payload, birth certificates, and an NDEATH will message. Many plants use both: the edge gateway is the OPC UA client on port 4840 and the Sparkplug edge node.

What is the difference between OPC UA and Modbus?

Modbus exposes registers and coils that a client polls. A vendor map says what each number means. OPC UA exposes named, typed variables with status codes and timestamps, plus subscriptions, methods, and certificate-based security. A PLC or gateway often polls Modbus and presents the points as OPC UA nodes. See Modbus TCP for port 502.

What port does OPC UA use?

The usual client/server port is TCP 4840, IANA name opcua-tcp. UDP 4840 is opcua-udp, used for PubSub multicast datagrams. IANA also registers TCP and UDP 4843 as opcua-tls. Sign and SignAndEncrypt on a normal opc.tcp endpoint stay on 4840. HTTPS and WebSocket endpoints use the port in their URL. The common ports cheat sheet lists 4840 and 4843.

How is OPC UA different from classic OPC DA?

Classic OPC DA is a Windows COM and DCOM interface for current values. OPC UA is the later platform-independent architecture, IEC 62541, with its own sessions and with TCP 4840 as the usual port. A wrapper can expose DA items as UA nodes. The client still speaks UA.

Does OPC UA replace PROFINET or EtherNet/IP?

Cyclic I/O stays on PROFINET or EtherNet/IP. OPC UA exposes information above the controller to SCADA, MES, and historians. Keep the field protocol in the cell and add OPC UA toward the rest of the plant. The full comparison chooses among those three I/O networks.

Related Protocols