Skip to content
Stand with Ukraine flag

S7

This documentation will help you configure the S7 protocol for your IoT gateway. We’ll explain the configuration parameters in simple terms to make it easy for you to understand and follow. The S7 protocol is commonly used for communication with Siemens PLCs. Follow the steps below to set up the S7 protocol in your IoT gateway. Use general configuration to enable this extension.

The S7 connector allows you to connect to Siemens S7 PLCs and collect data from them. It supports both S7-300 and S7-400 series PLCs, as well as the newer S7-1200 and S7-1500 series. Also, Siemens Logo! PLCs are supported. The connector uses the S7 protocol to communicate with the PLCs and retrieve data.

This configuration section contains general connector settings, such as:

  • Name - connector name used for logs and saving to persistent devices;
  • Logs configuration - settings for local and remote logging:
    • Enable remote logging - enables remote logging for the connector;
    • Logging level - logging level for local and remote logs: NONE, ERROR, CRITICAL, WARNING, INFO, DEBUG, TRACE;
  • Report strategy - strategy for sending data to ThingsBoard:
    • Report period - period for sending data to ThingsBoard in milliseconds;
    • Type - type of the report strategy:
      • On report period - sends data to ThingsBoard after the report period;
      • On value change - sends data to ThingsBoard when the value changes;
      • On value change or report period - sends data to ThingsBoard when the value changes or after the report period;
      • On received - sends data to ThingsBoard after receiving data from the device (default strategy).

Connector can be configured in “Advanced” configuration mode only for now. Below is a full example of the configuration file:

{
"devices": [
{
"type": "PLC",
"address": "127.0.0.1",
"port": 1102,
"rack": 0,
"slot": 1,
"deviceName": "S7 PLC",
"deviceProfileName": "default",
"autoReconnect": true,
"maxRetries": 3,
"retryDelay": 1,
"maxDelay": 30,
"heartbeatInterval": 0,
"pollPeriod": 10000,
"attributes": [
{
"type": "tag",
"key": "power",

Connector supports the following device types:

  • PLC - Siemens S7 PLCs (S7-300, S7-400, S7-1200, S7-1500);
  • LOGO - Siemens Logo! PLCs.

In the configuration file, you can specify the device type using the “type” parameter. The connector will use this parameter to determine how to communicate with the device. Also, each device type has its own set of parameters that can be configured. For example, the “PLC” device type has parameters for the rack and slot, while the “LOGO” device type has parameters for the TSAP.

This configuration section contains the list of devices that the connector will connect to. Each device has its own configuration, including the device type, address, port, and other settings. The connector supports both S7 PLCs and Siemens Logo! PLCs.

Configuration parameters for devices:

ParameterDefault valueDescription
devices[].typeDevice type: PLC or LOGO.
devices[].addressDevice IP address or hostname.
devices[].portDevice port number.
devices[].rack0Rack number for S7 PLCs (only for PLC type).
devices[].slot1Slot number for S7 PLCs (only for PLC type).
devices[].autoReconnecttrueEnable automatic reconnection to the device.
devices[].maxRetries3Maximum number of reconnection attempts.
devices[].retryDelay1.0Delay between reconnection attempts in seconds.
devices[].maxDelay30.0Maximum delay between reconnection attempts in seconds.
devices[].heartbeatInterval0Heartbeat interval in seconds.
devices[].tsapSnap7 **0TSAP for Siemens Logo! PLCs (only for LOGO type).
devices[].tsapLogo **0TSAP for Siemens Logo! PLCs (only for LOGO type).
devices[].deviceNameDevice name in ThingsBoard.
devices[].deviceProfileNameDevice profile name in ThingsBoard.
devices[].pollPeriod1000Polling period in milliseconds for reading data from the device.
devices[].reportPeriod1000(Optional) Report strategy object using for configuring report strategy for device.

Example of the PLC configuration:

{
"devices": [
{
"type": "PLC",
"address": "127.0.0.1",
"port": 1102,
"rack": 0,
"slot": 1,
"deviceName": "S7 PLC",
"deviceProfileName": "default",
"autoReconnect": true,
"maxRetries": 3,
"retryDelay": 1.0,
"maxDelay": 30.0,
"heartbeatInterval": 0,
"pollPeriod": 30000,
...
}
]
}

Example of the LOGO configuration:

{
"devices": [
{
"type": "LOGO",
"address": "127.0.0.1",
"port": 102,
"tsapSnap7": 20,
"tsapLogo": 30,
"deviceName": "LOGO",
"deviceProfileName": "default",
"autoReconnect": true,
"maxRetries": 3,
"retryDelay": 1,
"maxDelay": 30,
"heartbeatInterval": 0,
"pollPeriod": 1000,
...
}
]
}

In the data mapping, you can specify how the connector will interact with the device and what data it will read. You can also use this section to configure which data will be sent as device attributes or telemetry. Data mapping contains all the necessary settings for flexible data management.

The configuration in this unit provides settings for data processing. These settings will be interpreted in ThingsBoard platform instance as attributes/time series of the device.

PLC device data can be read in two ways: using data or tag parameters.

Use the following parameters for reading values from S7 PLCs by data type request:

ParameterDescription
devices[].attributes[].typeType of the parameter: data.
devices[].attributes[].keyKey name of the attribute parameter.
devices[].attributes[].dataTypeData type of the parameter. Please, refer to the Supported data types section.
devices[].attributes[].dbNumberDB number for S7 PLCs.
devices[].attributes[].startStart address for S7 PLCs.
devices[].attributes[].sizeSize of the parameter in bytes for S7 PLCs.
devices[].attributes[].bitBit number for S7 PLCs. Only for boolean values.
devices[].timeseries[].typeType of the parameter: data.
devices[].timeseries[].keyKey name of the time series parameter.
devices[].timeseries[].dataTypeData type of the parameter. Please, refer to the Supported data types section.
devices[].timeseries[].dbNumberDB number for S7 PLCs.
devices[].timeseries[].startStart address for S7 PLCs.
devices[].timeseries[].sizeSize of the parameter in bytes for S7 PLCs.
devices[].timeseries[].bitBit number for S7 PLCs. Only for boolean values.

Configuration example for reading values from S7 PLCs by data type request:

{
"attributes": [
{
"type": "data",
"key": "status",
"dataType": "bool",
"dbNumber": 0,
"start": 0,
"size": 1,
"bit": 1
}
],
"timeseries": [
{
"type": "data",
"key": "temperature",
"dataType": "float",
"dbNumber": 0,
"start": 2,
"size": 4
}
]
}

Use the following parameters for reading values from S7 PLCs by tag type request:

ParameterDescription
devices[].attributes[].typeType of the parameter: tag.
devices[].attributes[].keyKey name of the attribute or time series parameter.
devices[].attributes[].tagTag name for S7 PLCs. Please, refer to the Supported tag formats section.

Configuration example for reading values from S7 PLCs by tag type request:

{
"attributes": [
{
"type": "tag",
"key": "raw_data",
"tag": "DB0.DBB100:STRING[37]"
}
],
"timeseries": [
{
"type": "tag",
"key": "temperature",
"tag": "DB0.DBD104:REAL"
}
]
}

The Requests mapping section allows you to configure how the ThingsBoard platform instance will interact with the devices. That is, how the platform will request data from the devices, how it will update device attributes, and how it will send RPC commands to the devices.

S7 connector supports the following requests mapping:

  • Attribute updates - allows update device values from ThingsBoard platform instance.
  • RPC methods - allows sending RPC commands to devices. Using RPC methods, you can get or set values of the PLC. S7 connector supports different types of RPC methods. See the RPC methods section for more details.

This subsection contains configuration for attribute updates request from ThingsBoard platform instance.

ThingsBoard allows the provisioning of device attributes and fetches some of them from the device application. You can treat this as a remote configuration for devices, enabling them to request shared attributes from ThingsBoard. See user guide for more details.

The following parameters are used to configure attribute updates:

Same as reading attributes/time series, the S7 PLCs can be configured to update device attributes using data or tag parameters.

Use the following parameters to configure attribute updates for S7 PLCs by data type request:

ParameterDescription
devices[].attributeUpdates[].typeType of the parameter: data.
devices[].attributeUpdates[].keyKey name of the attribute parameter.
devices[].attributeUpdates[].dataTypeData type of the parameter. Please, refer to the Supported data types section.
devices[].attributeUpdates[].dbNumberDB number for S7 PLCs.
devices[].attributeUpdates[].startStart address for S7 PLCs.
devices[].attributeUpdates[].sizeSize of the parameter in bytes for S7 PLCs.
devices[].attributeUpdates[].bitBit number for S7 PLCs. Only for boolean values.

Configuration example for attribute updates for S7 PLCs by data type request:

{
"attributeUpdates": [
{
"type": "data",
"key": "isOpen",
"dataType": "bool",
"dbNumber": 1,
"start": 2,
"size": 1,
"bit": 1
}
]
}

Use the following parameters to configure attribute updates for S7 PLCs by tag type request:

ParameterDescription
devices[].attributeUpdates[].typeType of the parameter: tag.
devices[].attributeUpdates[].keyKey name of the attribute parameter.
devices[].attributeUpdates[].tagTag name for S7 PLCs. Please, refer to the Supported tag formats section.

Configuration example for attribute updates for S7 PLCs by tag type request:

{
"attributeUpdates": [
{
"type": "tag",
"key": "isOpen",
"tag": "DB1.DBX2.0:BOOL"
}
]
}

ThingsBoard allows sending RPC commands to the device that is connected to ThingsBoard directly or via Gateway. The S7 connector supports three main RPC approaches:

  • Configurable RPC to device - these methods allow you to configure custom RPC commands in connector configuration that can be sent to the devices.
  • Reserved GET/SET RPCs - reserved methods that allow reading or writing any address without manually configuring serverSideRpc. See the RPC guide.
  • Connector RPC - ad-hoc requests sent directly to the S7 connector for instant debugging and testing parameters from the ThingsBoard UI.

The parameters listed below are used specifically to configure RPCs to devices in the serverSideRpc section:

Same as reading atttributes/time series, the S7 PLCs can be configured to receive RPC commands using data or tag parameters.

Use the following parameters to configure RPC methods for S7 PLCs by data type request:

ParameterDescription
devices[].serverSideRpc[].methodRPC method name.
devices[].serverSideRpc[].requestTypeRPC request type: read or write.
devices[].serverSideRpc[].typeType of the parameter: data.
devices[].serverSideRpc[].dataTypeData type of the parameter. Please, refer to the Supported data types section.
devices[].serverSideRpc[].dbNumberDB number for S7 PLCs.
devices[].serverSideRpc[].startStart address for S7 PLCs.
devices[].serverSideRpc[].sizeSize of the parameter in bytes for S7 PLCs.
devices[].serverSideRpc[].bitBit number for S7 PLCs. Only for boolean values.

Configuration example for RPC methods for S7 PLCs by data type request:

{
"serverSideRpc": [
{
"method": "set_light",
"requestType": "write",
"type": "data",
"dataType": "bool",
"dbNumber": 1,
"start": 0,
"size": 1,
"bit": 1
},
{
"method": "get_light",
"requestType": "read",
"type": "data",
"dataType": "bool",
"dbNumber": 1,
"start": 0,
"size": 1,
"bit": 1
}
]
}

Use the following parameters to configure RPC methods for S7 PLCs by tag type request:

ParameterDescription
devices[].serverSideRpc[].methodRPC method name.
devices[].serverSideRpc[].requestTypeRPC request type: read or write.
devices[].serverSideRpc[].typeType of the parameter: tag.
devices[].serverSideRpc[].tagTag name for S7 PLCs. Please, refer to the Supported tag formats section.

Configuration example for RPC methods for S7 PLCs by tag type request:

{
"serverSideRpc": [
{
"method": "set_light",
"requestType": "write",
"type": "tag",
"tag": "DB1.DBX0.0:BOOL"
},
{
"method": "get_light",
"requestType": "read",
"type": "tag",
"tag": "DB1.DBX0.0:BOOL"
}
]
}

S7 connector supports PLC4X / Siemens STEP7 dialect tag syntax. The following table contains the supported tag syntax for S7 PLCs:

TagDescription
DB1.DBX0.0:BOOLBit in data block
DB1.DBB10:BYTEByte in data block
DB1.DBW10:INTWord (2 bytes)
DB1.DBD10:REALDouble word (4 bytes)
DB1:10:INTShort form (DB 1, offset 10)
DB1:10:STRING[20]Variable-length string
DB1:10:REAL[5]Array of 5 REALs
M10.5:BOOLMerker bit
MW20:WORDMerker word
I0.0:BOOLInput bit
Q0.0:BOOLOutput bit

S7 connector supports the following data types for both uplink and downlink:

  • Boolean & Bits: boolean/bool, bit.
  • Integers & Words: byte, usint, uint8, sint, int8, int, int16, short, uint, uint16, word, dint, int32, udint, uint32, dword, lint, ulint, lword.
  • Floating Point: real, float, float32, lreal, double, float64.
  • Characters & Strings: char, wchar, string/str/s7string, wstring, fstring.
  • Date & Time: time, ltime, tod, ltod, date, dt, ldt, dtl.
  • Raw Bytes: raw, bytes.