Siemens S7 to MQTT Integration (Step-by-Step Guide)

Content

In modern factories, Siemens S7 to MQTT Integration plays an increasingly vital role in connecting OT and IT systems. Siemens S7 controllers are renowned for their reliability and performance in automation, while MQTT provides a scalable, event-driven interface between OT and IT. As Siemens controllers remain widely used and MQTT adoption continues to grow, the demand for seamless integration is rising—especially in the context of the Industrial Unified Namespace (UNS) architecture. This step-by-step guide explains how to achieve a successful Siemens S7 to MQTT Integration.

 

Options for Siemens S7 to MQTT Integration

There are several approaches to connect a Siemens S7 controller with an MQTT broker: using a gateway, direct communication via the integrated LMQTT library, or through an OPC UA server. The best choice depends on your use case requirements and existing infrastructure. Below, we outline the main integration options, including their advantages and limitations. More details can be found here.

1. Option: Integration via Gateway

A gateway — either software or hardware — is one of the most common methods for Siemens S7 to MQTT integration. Acting as a bridge, the gateway reads data from the S7 controller, converts it into MQTT messages, and publishes them to the broker. This approach is especially useful for S7 controllers that do not natively support OPC UA or the LMQTT library.

Siemens S7 to MQTT Integration via Gateway

 

2. Option: Integration via S7 „LMQTT“ Library

Another effective method for integrating S7 controllers into MQTT networks is to use the “LMQTT” library. This library enables direct communication between the S7 controller and the MQTT broker without the need for an additional gateway. Using the library, the controller formats and sends data natively as MQTT messages.

Siemens S7 to MQTT Integration via LMQTT Library

 

3. Option: Integration via OPC UA Server

If the Siemens S7 controller supports an OPC UA server interface, it can be connected to MQTT through this interface. In practice, OPC UA and MQTT integration is typically achieved in two ways: either via a gateway or through direct communication using OPC UA over MQTT. This approach provides a flexible path for Siemens S7 to MQTT integration, especially in environments where OPC UA is already part of the infrastructure. Detailed explanations and step-by-step guidance can be found here.

 

Step-by-Step Guide to Integration via Gateway

Follow these steps to connect a Siemens S7 controller to an MQTT broker using a gateway.

Step 1: Verify Prerequisites

Before starting the integration, ensure that your infrastructure, systems, and permissions are properly configured to guarantee a reliable setup.

Select the right gateway: Confirm that the gateway natively supports both Siemens S7 and MQTT protocols. Check compatibility with other relevant systems in your OT/IT landscape (e.g., controllers, ERP) and make sure the gateway includes required security features. Depending on your use case, additional requirements such as redundancy or scalability may also be necessary.

Check infrastructure readiness: Verify that both the Siemens S7 controller and the MQTT broker are fully functional. Set up a test environment to validate the integration and adjustments before applying them in production.

Configure the network: Adjust your network topology as needed, including port and firewall settings, to enable communication while preventing unauthorized access.

Access and authorizations: Ensure you have the necessary access rights to the controller, the MQTT broker, and the gateway. Confirm that all required user permissions are in place, and install the relevant configuration software if needed.

 

Step 2: Identify Relevant S7 Data Blocks

Ensure that your Siemens S7 controller reliably provides the data points required for your use case. This involves selecting and validating the correct data blocks.

Identify S7 data blocks: Determine which data points (e.g., sensor readings, status information) are critical for your application.

Verify types and attributes: Check that the appropriate types (e.g., DB, FB, FC) and attributes (e.g., start address, length, access rights) are correctly assigned and configured in the controller.

 

Step 3: Define the MQTT Namespace

While S7 controllers define namespaces through data block configuration, the MQTT namespace is jointly established by publisher and subscriber. A standardized structure is essential for effective communication and scalable data organization.

Standardize the topic hierarchy: A topic is a UTF-8 string that specifies the path under which a message is published. Define clear naming rules for these topics, following best practices to ensure consistency and readability.

Standardize the MQTT message content (payload): The definition of a standardized payload is essential for interoperability and scalability, especially in heterogeneous machine environments. To do this, create a data model that includes the following components:

  • Uniform structure of the payload, including metadata (e.g. machine type and ID) and their representation within the MQTT topics
  • Standardized data format, for example JSON or XML, to simplify data processing and integration
  • Standardized data types and naming conventions to ensure the uniqueness and comprehensibility of the data.

 

Step 4: Map S7 Data Blocks to the MQTT Namespace

At this stage, you establish the connection between the gateway, the Siemens S7 controller, and the MQTT broker. The gateway serves as a bridge, translating S7 data blocks into standardized MQTT messages.

Test the connection: Verify connectivity between the S7 controller, the gateway, and the MQTT broker. Ensure compliance with security requirements, including proper configuration of authentication and encryption methods.

Map the MQTT payload: Assign relevant data from the S7 data blocks to the standardized data model defined in Step 3. If necessary, enrich the model with static inputs (e.g., machine type, machine ID).

Map the MQTT topics: Define how payloads are linked to MQTT topics. This may involve simple one-to-one mappings or more complex transformations, depending on the use case.

Implement transformation logic: Configure the gateway to handle necessary data conversions. These may include scaling measurement values, converting data types, or aggregating data points.

Mapping of Siemens S7 Data Blocks and MQTT Namespace

 

Step 5: Integration of S7 and MQTT in a Test Environment

Before moving to production, validate the integration in a dedicated test setup.

Define message transmission: Specify when control data should be published to MQTT. Best practice is to trigger updates on changes to specific data blocks, but fixed cycles (e.g., every second) can also be used. Configure key MQTT settings such as Quality of Service (QoS), Retain, and Report by Exception.

Verify data integrity: Ensure that data flows correctly from the controller through the gateway to the MQTT broker. Confirm that all security mechanisms—such as authentication and encryption—operate as expected.

 

Step 6: Go-Live and Monitoring

Once testing is complete, the integration can be deployed to production.

Go-live: Roll out the tested Siemens S7 to MQTT integration in the production environment.

Implement monitoring: Set up monitoring and alerting to track system performance and ensure reliable data transmission.

Enable logging and diagnostics: Maintain detailed logs for troubleshooting and continuous optimization of system performance.

 

Step-by-Step Guide to Integration via LMQTT Library

Since the general process is similar to the gateway approach, the specific steps for Siemens S7 to MQTT integration using the LMQTT library are outlined below. Note: Due to compatibility limitations and the typically limited availability of PLC programmers, this method is often less practical for brownfield environments.

1. Check prerequisites: Before starting, ensure the following requirements are met:

  • PLC programming resources: Skilled PLC programmers are needed to implement and configure the library on the controller.
  • Hardware and firmware compatibility: Confirm that your controller (e.g., S7-1200 or S7-1500) provides the necessary resources. For secure TLS communication, firmware version 2.0 (S7-1200) or 4.4 (S7-1500) or higher is required.
  • Programming environment: The TIA Portal is mandatory for implementation.
  • Network interface: The controller must have an Ethernet interface to support message exchange via TCP/IP.

2. Create a TIA Portal project: Create a new project in the TIA Portal for S7-1200 or S7-1500 CPU. Configure the CPU’s Ethernet IP address so it is in the same subnet as the MQTT broker.

3. Add the “LMQTT” library: Download the LMQTT library and add it to your project. In the “Global Libraries” section, open the library and drag the LMQTT_Client function block (FB) into your project.

4. Create a global data block (DB): Define a new global data block for TCP/MQTT connection parameters as well as the messages to be published and received.

5. Integrate FB “LMQTT_Client”: Insert the LMQTT_Client FB into the main program (e.g., OB1) and link the required tags from the global DB.

6. Configure MQTT Settings: If secure communication is required, import the MQTT broker’s TLS certificate. Configure the FB to use the certificate for encrypted data exchange.

7. Test S7 to MQTT integration: Set all necessary connection parameters in the DB, load the program onto the CPU and start the connection to the MQTT broker.

 

Conclusion

Combining Siemens S7 controllers with MQTT enables smarter, connected production. Success depends on selecting the right integration method and establishing a sustainable strategy. With consistent mapping of S7 data blocks to the MQTT namespace across systems and factories, companies can boost efficiency, productivity, and competitiveness. In brownfield environments, this is typically achieved via a gateway that ensures standardization and scalability of the MQTT namespace enterprise-wide.

About i-flow: i-flow is an industrial software company based in southern Germany. We offer manufacturers the world’s most intuitive software to connect factories at scale. Over 400 million data operations daily in production-critical environments not only demonstrate the scalability of the software, but also the deep trust our customers place in i-flow. Our success is based on close collaboration with customers and partners worldwide, including renowned Fortune 500 companies and industry leaders like Bosch.

Try it out now - free trial version

Experience the unlimited possibilities that i-flow offers by taking a test for yourself. Test now for 30 days free of charge on your systems.

Related Articles

Your question has not been answered? Contact us.

Eine Frau mit braunen Haaren, einem dunkelblauen Hemd und einer hellen Hose steht lächelnd mit den Händen in den Taschen vor einem steinernen Gebäude mit großen Fenstern.

Your Contact:

Marieke Severiens (i-flow GmbH)
content@i-flow.io