Connecting & Integrating a Siemens S7 Device
How to integrate Siemens SIMATIC S7 PLCs with Connectware for seamless industrial data exchange.
This guide explains how to connect a Siemens SIMATIC S7 PLC to Connectware, enabling seamless data exchange between your industrial automation equipment and modern applications via MQTT.
The Siemens SIMATIC S7 is a widely used line of PLCs (Programmable Logic Controllers) in industrial automation. These controllers connect to sensors and actuators via digital or analog IOs, and data exchange is achieved using S7 communication services based on ISO-on-TCP (RFC1006).
In this setup, the PLC acts as a server, allowing external applications to access PLC data without requiring explicit incoming connection configuration during PLC programming. Connectware leverages this capability to enable real-time monitoring and control.
By the end, you will have a working setup that allows you to:
Prepare your S7 device (or an emulator) for communication with Connectware.
Create and configure a service commissioning file in YAML format.
Map PLC data to MQTT topics for both monitoring and control.
Test your connection with either a real PLC or the Conpot PLC emulator.
Prerequisites
To follow this guide, you will need the following:
A running instance of Cybus Connectware.
Access to the Admin UI with sufficient user permissions.
Basic knowledge of MQTT and the Connectware services concept (e.g. service commissioning files, connections, and endpoints).
System Requirements and Setup Options
To complete this guide, you need a running Connectware instance, and one of the following:
1. Using a Siemens S7 PLC with STEP7 (TIA Portal)
Configure the S7 using STEP7. Ensure the following settings on your S7 device:
Enable PUT/GET access in the PLC settings to activate S7 Communication Services. Note that this allows other applications to access the controller.
Disable Optimized Block Access in the data block attributes to allow access to data blocks.
2. Using the Conpot PLC Emulator
You can use Conpot to emulate a Siemens S7 PLC for testing purposes.
Example: Service Commissioning File
You can download the example service commissioning file used in this guide from the Cybus GitHub repository.
Creating the Service Commissioning File
The YAML-based service commissioning file tells Connectware what type of device to connect, how to configure the connection, and which endpoints to access. For more details, see Service Commissioning Files.
Here, we focus on the three main resources:
In the following sections, we will walk through each resource and build an example service commissioning file to connect to an S7 device and enable read/write access to a data endpoint.
Step 1 - Defining the Connection
Within the resources
section of the service commissioning file, define a connection to your device. This includes all information Connectware needs to communicate with the device, such as protocol, IP address, and more. The Cybus::Connection
resource specifies how Connectware communicates with the PLC.
Example
# ----------------------------------------------------------------------------#
# Connection Resource - S7 Protocol
# ----------------------------------------------------------------------------#
s7Connection:
type: Cybus::Connection
properties:
protocol: S7
connection:
host: 192.168.10.60
port: 102
rack: 0
slot: 1
pollInterval: 1000
Here, we define a Cybus::Connection
resource using the S7 protocol. The connection settings specify the device's IP address, port, rack, and slot numbers. The pollInterval
determines how often data is read from the device (in milliseconds).
Step 2 - Defining an Endpoint
The Cybus::Endpoint
resource defines a specific PLC memory location to access.
# ----------------------------------------------------------------------------#
# Endpoint Resource - S7 Protocol
# ----------------------------------------------------------------------------#
s7EndpointDB1000:
type: Cybus::Endpoint
properties:
protocol: S7
connection: !ref s7Connection
subscribe:
address: DB10,X0.0
This endpoint represents a data element on the device. The protocol
and connection
reference are required, as before. The subscribe
section specifies the memory address to read from. In this example, we read a boolean value from data block 10 (DB10), byte 0, bit 0 (X0.0). For more on S7 addressing, see Siemens S7 Endpoint Properties.
Step 3 – Mapping to MQTT
The Cybus::Mapping
resource links PLC endpoints to MQTT topics.
# ----------------------------------------------------------------------------#
# Mapping Resource - S7 Protocol
# ----------------------------------------------------------------------------#
mapping:
type: Cybus::Mapping
properties:
mappings:
- subscribe:
endpoint: !ref s7EndpointDB1000
publish:
topic: !sub '${Cybus::MqttRoot}/DB1000'
This mapping transfers data from the endpoint to a specified MQTT topic. The subscribe
section references the endpoint, and the publish
section defines the MQTT topic. The !sub
syntax substitutes variables such as ${Cybus::MqttRoot}
.
Complete Example: Service Commissioning File
Combining the previous sections, a complete service commissioning file looks like this:
description: >
S7 Example
metadata:
name: S7 Device
resources:
# ----------------------------------------------------------------------------#
# Connection Resource - S7 Protocol
# ----------------------------------------------------------------------------#
s7Connection:
type: Cybus::Connection
properties:
protocol: S7
connection:
host: 192.168.10.60
port: 102
rack: 0
slot: 1
pollInterval: 1000
# ----------------------------------------------------------------------------#
# Endpoint Resource - S7 Protocol
# ----------------------------------------------------------------------------#
s7EndpointDB1000:
type: Cybus::Endpoint
properties:
protocol: S7
connection: !ref s7Connection
subscribe:
address: DB10,X0.0
# ----------------------------------------------------------------------------#
# Mapping Resource - S7 Protocol
# ----------------------------------------------------------------------------#
mapping:
type: Cybus::Mapping
properties:
mappings:
- subscribe:
endpoint: !ref s7EndpointDB1000
publish:
topic: !sub '${Cybus::MqttRoot}/DB1000'
Step 4 - Enabling Write Access
To write data to the device, define another endpoint using
write
instead ofsubscribe
:
s7EndpointDB1000Write:
type: Cybus::Endpoint
properties:
protocol: S7
connection: !ref s7Connection
write:
address: DB10,X0.0
Extend your mappings to transfer data from a specific MQTT topic to the write endpoint:
mapping:
type: Cybus::Mapping
properties:
mappings:
- subscribe:
endpoint: !ref s7EndpointDB1000
publish:
topic: !sub '${Cybus::MqttRoot}/DB1000'
- subscribe:
topic: !sub '${Cybus::MqttRoot}/DB1000/set'
publish:
endpoint: !ref s7EndpointDB1000Write
To write a value, publish a message to the topic (e.g.,
services/s7device/DB1000/set
) with the following payload:
{ "value": true }
Installing and Using the Service
Install the service commissioning file. See Installing Services.
Enable the service. See Enabling Services.
Once the service is installed and enabled, you can monitor the S7 data:
To change a value, use any MQTT client (e.g., Mosquitto) to publish a new value to the corresponding topic as described in the Writing Data section.
Summary
You have learned how to:
Connect an S7 PLC (or emulator) to Connectware
Create a service commissioning file for reading/writing data
Map PLC data to MQTT topics
For more advanced usage, see Siemens SIMATIC S7 Protocol Details.
Last updated
Was this helpful?