Siemens S7 Flux Asset
Introduction
The Siemens S7 Connector is a flux asset provided by Coreflux that facilitates seamless communication between Siemens S7 PLCs (Programmable Logic Controllers) and your data hub. This guide offers a comprehensive overview of the Siemens S7 Connector, detailing its features, benefits, installation, configuration, and usage.
What is Siemens S7?
Siemens S7 is a family of PLCs developed by Siemens for automation tasks in industrial processes. These controllers are widely used in various industries due to their reliability, flexibility, and performance.
Features and Benefits
- Seamless Communication: Enables direct communication between Siemens S7 PLCs and your data hub.
- Real-time Monitoring: Allows real-time monitoring of Siemens S7 PLCs.
- Easy Integration: Simplifies the integration of Siemens S7 PLCs with your IIoT projects.
- Configurable Parameters: Offers a range of parameters to customize the connection to your specific needs.
Prerequisites
Before you install and configure the Siemens S7 Connector, ensure you have the following prerequisites:
- Basic understanding of the MQTT protocol;
- Coreflux account;
- Coreflux v1.2 or higher;
- Coreflux MQTT Broker;
- MQTT Client (e.g., MQTT Explorer);
- Access to a Siemens S7 PLC.
Connector Installation
Using Coreflux HUB
Please refere to general docs for connector installation through the Coreflux HUB.
Using Coreflux HUBLESS
Connector management and control are conducted using the MQTT protocol. Commands (payload) are sent to the $SYS/Coreflux/Command topic. The results of these commands are published to $SYS/Coreflux/Command/Output. The following steps will focus solely on the payload that needs to be sent.
- Connect to the Coreflux MQTT Broker using your preferred client;
- Login using your coreflux account:
- Check your available connectors:
- Install the connector:
- If there were no issues during the installation, you should receive a message on the $SYS/Coreflux/Command/Output topic:
Connector Configuration
Coming from version <1.0? Please refer to this section
More information on the configuration on TIA Portal is available on this section
Before using the connector, it must be properly configured. This configuration process entails adjusting various parameters that affect its functionality, the setup of the device, and how they interact with each other. This involves specifying the device's IP address and selecting which symbols to read from the device, among other settings. The configuration is detailed in a JSON file, divided into three main sections: MQTT Parameters, Siemens S7 Parameters and Tag Parameters.
The instructiosn bellow will guide you through configuring each section.
By the end, you will have a comprehensive example configuration that can be tailored to your specific needs.
Warning: If a parameter is not included in your connector's configuration and it is not required, a default value will be applied. Incorrect configuration may cause the connector to not work as intended.
Information source: This configuration is presented using a hubless setup as an example. The key takeaway is the understanding of the parameters and their significance. If you are configuring the connector via Coreflux Hub, the same parameters and configurations apply.
MQTT Parameters
The MqttParameters in the JSON configuration define how to connect to an MQTT broker, specifying the communication details. The Address and Port indicate the broker's network location (in this case, 127.0.0.1 on port 1883), which is where the data will be sent to or received from. The parameters also detail authentication methods and the use of TLS for secure communication. This setup determines the pathway for data exchange between the device and the MQTT broker, facilitating the monitoring or control of device operations.
Parameter | Description | Required | Example | Default Value |
---|---|---|---|---|
Port | Port number on which the MQTT broker is running. | Yes | 1883 |
1883 |
Address | IP address or hostname of the MQTT broker. | Yes | "127.0.0.1" |
"127.0.0.1" |
IsAnonymous | Indicates if the connection is anonymous (no username/password required). | No | true |
true |
Username | Username for authentication, if not anonymous. | No | "" |
"" |
Password | Password for authentication, if not anonymous. | No | "" |
"" |
WithTLS | Specifies whether TLS encryption is enabled for secure communication. | No | true |
false |
Example:
{
"MqttParameters": {
"Port": 1883,
"Address": "127.0.0.1",
"IsAnonymous": true,
"Username": "",
"Password": "",
"WithTLS": false
}
}
Siemens S7 Parameters
The Siemens S7 Parameters in the JSON configuration specify the setup for the Siemens S7 communication between the PLC and the connector.
These parameters require the PLC's IP address, rack and slot, as well as the retry attempts, the retry time, in seconds, the refresh time, in milliseconds, and the connection type to the PLC.
Check here which rack and slot to use for your device.
Parameter | Description | Required | Example | Default Value |
---|---|---|---|---|
IP | The PLC device IP address | Yes | "127.0.0.1" |
"" |
PLCRack | The rack number of the PLC in the hardware configuration | Yes | 0 |
0 |
PLCSlot | The slot number of the CPU in the PLC rack | Yes | 1 |
1 |
ConnectionType | Specifies the type of connection to the PLC. For more details, refer to this section |
Yes | 3 |
1 |
RefreshTimeInMs | The time interval (in milliseconds) for refreshing data from the PLC. Defines how often the system polls the PLC for updates | Yes | 200 |
0 |
Retries | The number of retry attempts if the connection to the PLC fails | No | 2 |
0 |
RetryTimeInSeconds | The time interval (in seconds) between connection retries | No | 5 |
0 |
Example:
{
"MqttParameters": {
"Port": 1883,
"Address": "127.0.0.1",
"IsAnonymous": true,
"Username": "",
"Password": "",
"WithTLS": false
},
"SiemensS7Parameters":{
"IP": "192.168.0.1",
"PLCRack": 0,
"PLCSlot": 1,
"ConnectionType": 3,
"RefreshTimeInMs": 200,
"Retries": 2,
"RetryTimeInSeconds":5
}
}
Tags
Tags are crucial components that simplify the set of actions the connector will perform in the workspace.
Each Tag in the configuration represents a unique connection between a MQTT topic and a Siemens S7 PLC variable. The parameters for each tag include the Variable Type, the Data Block Value, the String Size, the Byte, the Bit, the Data Type and the Behaviour.
Parameter | Description | Required | Example | Default Value |
---|---|---|---|---|
Name | Unique Tag Identifier | Yes | "RoomTemperature" |
"TagName" |
Route | Specifies the direction of data flow within the system. Acceptable values are: 'ToSubscribers' (0), 'ToOther' (1). |
Yes | 0 |
1 |
Publish | Choose how data is sent. Acceptable values are: 'Update' (0), 'Cyclic' (1), 'Once' (2) |
Yes | 0 |
2 |
PublishCycle | Specifies the interval for publishing messages when 'publish' is set to 'Cyclic'. Must be a value between 1 and 86,400 seconds (24 hours). |
No | 500 |
1 |
MqttTopic | Unique Topic connecting with the specified Register | Yes | "room/temp" |
"mqtt/topic" |
MqttRetain | Defines if the message should be retained. Options are: true or false. |
Yes | true |
false |
QualityOfService | Defines the level of delivery assurance for MQTT messages. The options are: 'AtMostOnce' (0), 'AtLeastOnce' (1), 'ExactlyOnce' (1). |
Yes | 2 |
2 |
VariableType | Where the data is stored in the PLC. Options are 'Memory' (0), 'Input' (1), 'Output' (2) and 'DataBlock' (3) |
Yes | 1 |
0 |
DataBlockValue | The data block number where the value to read is located, when Variable Type is Data Block | Conditional | 3 |
0 |
Byte | The starting byte | Yes | 0 |
0 |
Bit | Specific bit within the byte | Yes | 3 |
1 |
DataType | Type of data stored at a specific location in the PLC. Options are 'BOOL' (0), 'BYTE' (1), 'INT' (2), 'WORD' (3), 'DINT' (4), 'REAL' (5), 'STRING' (6), , 'DWORD' (7) |
Yes | 6 |
0 |
StringSize | Defines the max length for the string, when Data Type is String | Conditional | 10 |
0 |
Behaviour | Tag behaviour when a value is read/received. Options are 'TriggerOnlyDifferent' (0) or 'TriggerAlways' (1) |
Yes | 1 |
0 |
Example:
{
"MqttParameters": {
"Port": 1883,
"Address": "127.0.0.1",
"IsAnonymous": true,
"Username": "",
"Password": "",
"WithTLS": false
},
"SiemensS7Parameters":{
"IP": "192.168.0.1",
"PLCRack": 0,
"PLCSlot": 1,
"ConnectionType": 3,
"RefreshTimeInMs": 200,
"Retries": 2,
"RetryTimeInSeconds":5
},
"Tags":
[
{
"Name" : "FromMqttToS7",
"Route" : 1,
"Publish" : 0,
"PublishCycle" : 127,
"MqttTopic" : "set/temp",
"MqttRetain" : true,
"QualityOfService" : 0,
"VariableType": 1,
"Byte": 0,
"Bit": 1,
"DataType": 6,
"Behaviour": 1
},
{
"Name":"FromS7ToMqtt",
"Route": 0,
"Publish" : 0,
"PublishCycle" : 127,
"MqttTopic" : "read/temp",
"MqttRetain" : true,
"QualityOfService" : 0,
"VariableType": 3,
"DataBlockValue": 2,
"Byte": 0,
"Bit":0,
"DataType":3,
"Behaviour":0
}
]
}
Saving the Configuration
Connector management and control are conducted using the MQTT protocol. Commands (MQTT payload) are sent to the $SYS/Coreflux/Command topic. The results of these commands are published to $SYS/Coreflux/Command/Output. The following steps will focus solely on the payload that needs to be sent.
ℹ : Configuration requires the user to be logged in and have an connector installed. If these requirements are not met, please refer to the installation section.
- Save the configuration:
ℹ : The asset asset_guid can be obtained by consulting the $SYS/Coreflux/Assets topic.
Example:
-assetConfigSave assetName {
"MqttParameters": {
"Port": 1883,
"Address": "127.0.0.1",
"IsAnonymous": true,
"Username": "",
"Password": "",
"WithTLS": false
},
"SiemensS7Parameters":{
"IP": "192.168.0.1",
"PLCRack": 0,
"PLCSlot": 1,
"ConnectionType": 3,
"RefreshTimeInMs": 200,
"Retries": 2,
"RetryTimeInSeconds":5
},
"Tags":
[
{
"Name" : "FromMqttToS7",
"Route" : 1,
"Publish" : 0,
"PublishCycle" : 127,
"MqttTopic" : "set/temp",
"MqttRetain" : true,
"QualityOfService" : 0,
"VariableType": 1,
"Byte": 0,
"Bit": 1,
"DataType": 6,
"Behaviour": 1
},
{
"Name":"FromS7ToMqtt",
"Route": 0,
"Publish" : 0,
"PublishCycle" : 127,
"MqttTopic" : "read/temp",
"MqttRetain" : true,
"QualityOfService" : 0,
"VariableType": 3,
"DataBlockValue": 2,
"Byte": 0,
"Bit":0,
"DataType":3,
"Behaviour":0
}
]
}
Using the Connector
⚠ : It is important to understand that the flow of data between the broker and the device highly depends on the configuration of both the connector and the device. In case of unexpected results, please verify the configuration and/or check the logs for any possible errors.
With Coreflux HUB
Please refer to the general docs for connector installation through the Coreflux HUB.
With Coreflux HUBLESS
Connector management and control are conducted using the MQTT protocol. Commands (MQTT payload) are sent to the $/Coreflux/Command topic. The results of these commands are published to $/Coreflux/Command/Output. The following steps will focus solely on the payload that needs to be sent.
ℹ : The asset guid can be obtained by consulting the $SYS/Coreflux/Assets topic.
Run Connector
- Run connector:
Stop Connector
- Stop connector:
Logs
Logs are essential to monitor and debug your system. They provide insight into the operation of your connectors and can help identify and resolve issues promptly.
With Coreflux HUB
On Coreflux HUB, the logs are displayed in the "Log" section of the connector configuration.
With MQTT Explorer
To display logs in MQTT Explorer, follow these steps:
- Publish the following command to the $/Coreflux/Command topic:
Example1:
To display informational
logs, use:
Note : This will display the Logs "Information" of
all the connectors
Example2:
To display error logs, from a specific connector, use:
Note : This will display the Logs "Error" of a
specific connector
Note: To display all three types of logs (Error, Information, and Warning), you will need to repeat this process three times, one for each log level. three times, one for each log level.
FAQ
General Questions
What is the Siemens S7 Connector?
The Siemens S7 Connector is a flux asset provided by Coreflux that enables seamless communication between Siemens S7 PLCs and your data hub. It allows you to monitor them in real-time and easily integrate them with your IIoT projects.
What are the prerequisites for using the Siemens S7 Connector?
Before you install and configure the Siemens S7 Connector, ensure you have the following prerequisites:
- Basic understanding of the MQTT protocol;
- Coreflux account;
- Coreflux v1.2 or higher;
- Coreflux MQTT Broker asset;
- MQTT Client (e.g., MQTT Explorer);
- Access to a Siemens S7 PLC.
How do I install the Siemens S7 Connector?
The Siemens S7 Connector can be installed via GUI or command-line. Detailed installation instructions can be found in the Installation section of the Siemens S7 Connector documentation.
Configuration Questions
How do I configure the Siemens S7 Connector?
To configure the Siemens S7 Connector, you need to run only one command:
The<guid>
is a unique asset id that is generated during the installation. To retrieve the connector guid, refer to the $SYS/Coreflux/Assets
topic.
The <configuration>
parameter is where you are able to set the asset settings. Detailed configuration instructions and an example configuration can be found in the Configuration section of the Siemens S7 Connector documentation.
What are the parameters in the configuration?
The configuration consists of three main sections: MQTTParameters
, SiemensS7Parameters
, and Tags
.
- MQTTParameters
are used to configure the connection between the client and the MQTT broker.
- SiemensS7Parameters
are used to configure the connection between the MQTT Broker and the Siemens S7 PLC.
- Tags
is an array of "Tag", each containing parameters for a unique PLC variable and MQTT topic connection.
Details of each parameter can be found in the Configuration section of the Siemens S7 Connector documentation.
Usage Questions
How do I run the Siemens S7 Connector?
To run the Siemens S7 Connector, publish the “-R” (run) command with the asset guid to $SYS/Coreflux/Cloud/Command
topic:
Troubleshooting Questions
The Siemens S7 Connector is not running, what should I do?
Ensure that you have correctly installed and configured the Siemens S7 Connector. Check the $SYS/Coreflux/Assets
topic to confirm that the asset guid is correct. If the problem persists, join our Discord community for help.
I am not receiving any data, what should I do?
Ensure that the Siemens S7 Connector Asset is running and that the MQTT client is correctly configured. Check the DebugTopic
specified in the Simenens S7 Parameters
section of the configuration for any connection state feedback. If the problem persists, join our Discord community for help.
Configuration Conversion Tool
If you had an older version of the SiemensS7 connector and want to reuse the configuration, please refer to the repository Coreflux Configuration Conversion Tool to make it compatible with the new connector configuration!
Tia Portal
Accessing Datablock Variables
For the connector to access datablock variables, there's a need to set the memory offset on the PLC, through the Tia Portal.
Enabling “Connection mechanisms” in Tia Portal
Due to a series of hacking incidents targeting the Siemens Tia Portal, especially the S7-1200 and S7-1500 series, Siemens introduced a solution where the user decides if remote partners can access to read/write the internal variables of the devices they're connecting to.
For the S72MQTT Flux asset to read/write into the PLC, it's essential to activate the PUT/GET communication access. Here's how to do it:
- Connect to Your PLC: Connect your Tia Portal project to your target PLC and then navigate to “Local modules” and select your PLC CPU.
- Access Properties: Double-click on the device or go to Properties and scroll down to select “Protection & Security”.
- Connection Mechanisms: Open “Protection & Security” and select “Connection mechanisms”.
- Enable PUT/GET: Ensure the option “Permit access with PUT/GET communication from remote partner” is selected.
- Compile and Download: Compile and download your updated hardware configuration.
PLC Rack and Slot Configuration
These two elements must align with the configuration of the running PLC.
Typically, it should be PLC Rack=0 and PLC Slot=1. However, you can verify this configuration in TiaPortal: Navigate to Devices > Device Configuration > click on CPU > Project Information. In this example, it would show Rack 0, Slot 1.
Rack and Slot Configuration for different Siemens PLCs
PLC Model | Rack | Slot | Notes |
---|---|---|---|
S7-300 | 0 | 2 | Always like this |
S7-400 | Defined in project | Defined in project | Follow hardware configuration in Tia Portal or STEP 7 |
WinAC | Defined in project | Defined in project | Follow hardware configuration in Tia Portal or STEP 7 |
S7-1200 | 0 | 0 or 1 | - |
S7-1500 | 0 | 0 or 1 | - |
WinAC IE | 0 | 0 or follow hardware configuration | - |
Connection Resource
By default, the client connects as a PG (1) (the programming console). With this function, it's possible to change the connection resource type to OP (2) or S7 Basic (3-10) (a generic data transfer connection).
In the hardware configuration (Simatic Manager) of the CPU, under the “Communication” tab, you can modify, PLC-side, the connection's distribution. Essentially, this represents a protocol resource on the PLC side.