0
0
Drone-programmingComparisonIntermediate · 4 min read

OPC UA vs MQTT for Industrial IoT: Key Differences and Usage

In Industrial IoT, OPC UA is a complex, secure protocol designed for rich data modeling and device interoperability, while MQTT is a lightweight, publish-subscribe messaging protocol ideal for simple, low-bandwidth communication. Choose OPC UA for detailed device integration and MQTT for efficient telemetry data transfer.
⚖️

Quick Comparison

This table summarizes the main differences between OPC UA and MQTT for Industrial IoT.

FactorOPC UAMQTT
Protocol TypeService-oriented architecture with rich data modelsLightweight publish-subscribe messaging
Data ModelComplex, supports hierarchical and semantic dataSimple, message payload only
SecurityBuilt-in encryption, authentication, and authorizationDepends on external TLS and broker security
Communication PatternClient-serverPublish-subscribe
Use CaseDevice interoperability and controlTelemetry and event messaging
Resource UsageHigher CPU and memory needsLow bandwidth and resource usage
⚖️

Key Differences

OPC UA is designed for industrial environments needing detailed device information and control. It uses a client-server model where clients request data or commands from servers that represent devices. Its rich data model allows representing complex relationships and metadata, making it ideal for device interoperability and process control.

In contrast, MQTT is a simple, lightweight protocol using a publish-subscribe model. Devices publish messages to topics on a broker, and other devices subscribe to those topics to receive data. MQTT is optimized for low bandwidth and unreliable networks, making it perfect for telemetry data and event notifications.

Security in OPC UA is built-in with encryption, authentication, and authorization features. MQTT relies on external security layers like TLS and broker access control. This makes OPC UA more secure out of the box but also more complex to set up.

⚖️

Code Comparison

python
from opcua import Client

url = "opc.tcp://localhost:4840"
client = Client(url)
try:
    client.connect()
    root = client.get_root_node()
    print("Root node is:", root)
    # Read a variable node value
    var = client.get_node("ns=2;i=2")
    value = var.get_value()
    print("Value of node ns=2;i=2 is", value)
finally:
    client.disconnect()
Output
Root node is: Node(Identifier=ns=0;i=84) Value of node ns=2;i=2 is 42
↔️

MQTT Equivalent

python
import paho.mqtt.client as mqtt

broker = "test.mosquitto.org"
topic = "industrial/sensor1"

# Callback when a message is received
def on_message(client, userdata, msg):
    print(f"Received message: {msg.payload.decode()} on topic {msg.topic}")

client = mqtt.Client()
client.on_message = on_message
client.connect(broker, 1883, 60)
client.subscribe(topic)
client.loop_start()

# Publish a test message
client.publish(topic, "42")

import time
time.sleep(2)
client.loop_stop()
client.disconnect()
Output
Received message: 42 on topic industrial/sensor1
🎯

When to Use Which

Choose OPC UA when you need detailed device integration, secure communication, and complex data models for industrial automation and control systems. It fits well where devices must interoperate with rich metadata and strict security.

Choose MQTT when your focus is on lightweight, efficient telemetry data transfer over unreliable or low-bandwidth networks. It is ideal for simple sensor data, event notifications, and cloud communication where minimal overhead is critical.

Key Takeaways

OPC UA offers rich data modeling and built-in security for complex industrial device integration.
MQTT is lightweight and efficient, perfect for simple telemetry and event messaging.
Use OPC UA for secure, detailed control and MQTT for scalable, low-bandwidth communication.
OPC UA uses client-server; MQTT uses publish-subscribe communication patterns.
Security is native in OPC UA, while MQTT depends on external TLS and broker controls.