Modul 4 von 9 · 📖 4 min Lesezeit · ⏱ 30 min gesamt
FI-DV 04 MQTT und Sparkplug B (EN)
Inhaltsverzeichnis (6 Abschnitte)
FI-DV 04 MQTT and Sparkplug B
MQTT (Message Queuing Telemetry Transport) is a lightweight Publish/Subscribe protocol designed for efficient data transmission in networked systems. In this module, you will learn the fundamentals of MQTT architecture, understand the different Quality-of-Service levels, and master handling Retained Messages. You will gain insights into security concepts for MQTT installations and learn about the specifics of the Sparkplug B standard for standardizing industrial applications.
The practical application is in focus: You will configure an MQTT broker, implement client applications, and integrate Sparkplug B for seamless communication between devices and applications. Upon completion of this module, you will be able to plan and implement MQTT-based solutions for industrial automation and IoT applications.
Concepts and Background
- MQTT Broker
- The central instance that receives all messages from publishers and forwards them to the appropriate subscribers. The broker manages the topics and establishes the connection between the clients.
- Quality of Service (QoS)
- Three levels (0, 1, 2) that define the reliability of message transmission. QoS 0 provides "at most once" delivery, QoS 1 "at least once" and QoS 2 "exactly once" with increased overhead.
- Retained Messages
- Messages stored by the broker that are sent to new subscribers that subscribe to a topic. This ensures that new clients immediately receive the current state.
- Sparkplug B
- An open standard that extends MQTT with semantic structures. It defines a fixed topic format and message schema for monitoring, control, and data acquisition in industrial applications.
- Willow-Way Topic Hierarchy
- The standardized topic structure of Sparkplug B, which allows a clear separation between metadata (NDATA), payload data (DDATA) and commands (CMD) and enables hierarchical organization of devices.
Architecture Diagram
flowchart TD
A[Edge Device] -->|Publish/Subscribe| B[MQTT Broker]
C[SCADA System] -->|Subscribe| B
D[Historian] -->|Subscribe| B
E[IIoT Platform] -->|Publish/Subscribe| B
F[Human Machine Interface] -->|Subscribe| B
B -->|Sparkplug B| G[Application Server]
style A fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#bbf,stroke:#333,stroke-width:2px
style G fill:#bfb,stroke:#333,stroke-width:2px
Practical Steps
- Install the Eclipse Mosquitto MQTT broker on a Linux system with the command
. This provides the basic infrastructure for MQTT communication.sudo apt install mosquitto mosquitto-clients - Configure the broker's security by creating a password file with
and adjusting the configuration inmosquitto_passwd -c /etc/mosquitto/passwortfile username
. This protects the broker from unauthorized access.listener 1883 allow_anonymous false password_file /etc/mosquitto/passwortfile - Create a test environment with two terminals: One for the publisher (
) and one for the subscriber (mosquitto_pub -h localhost -u username -P password -t test/topic -m "Hello MQTT"
). This verifies the basic functionality.mosquitto_sub -h localhost -u username -P password -t test/topic - Implement Sparkplug B compatibility by installing the library
and creating a Node-Birth packet withpip install sparkplugbpayload
. This initializes a Sparkplug-capable device.from sparkplugbpayload import SparkplugBPayload payload = SparkplugBPayload("NBIRTH") payload.add_metric("Node Control/Rebirth", "boolean", False) payload.serialize() - Configure Retained Messages for critical state data with
. This ensures that new clients immediately receive the current device status.mosquitto_pub -r -t device/status -m "online" - Test the different QoS levels by sending messages with
,mosquitto_pub -q 0 -t qos/test -m "QoS 0"
andmosquitto_pub -q 1 -t qos/test -m "QoS 1"
and observing the behavior in the subscriber. This helps in selecting the appropriate QoS for your application.mosquitto_pub -q 2 -t qos/test -m "QoS 2"
Common Pitfalls
Further Resources
- OASIS MQTT 5.0 Specification - The official documentation of the MQTT standard
- Sparkplug B Specification - The complete specification of the Sparkplug B standard
- Mosquitto Configuration Documentation - Detailed explanations of all configuration parameters
- Eclipse Mosquitto GitHub Repository - Source code and additional resources
- HiveMQ MQTT QoS Guide - Comprehensive explanation of QoS levels with practical examples
Knowledge Check
Four questions for self-assessment. Click on each question to see the correct answer and explanation.
What is the main task of an MQTT broker in a Publish/Subscribe system?
- A) Ensure encryption of all messages
- B) Receive messages from publishers and forward them to appropriate subscribers
- C) Perform authentication of all clients in the network
- D) Guarantee data persistence for all messages
Correct Answer: B. The broker acts as an intermediary that forwards messages based on the topics a