Skip to content
Vita edited this page Mar 23, 2022 · 24 revisions

Introduction

This binding for openHAB 3 has ability to connect Simatic PLC over Ethernet with isoTCP. So it is possible to connect to the Simatic PLC S7-200, S7-300, S7-400, S7-1200 and S7-1500 series. H-system is not supported.

Binding uses libnodave library to provide connection (https://sourceforge.net/projects/libnodave/).

Installation

Installation from openHAB Marketplace is recommended.

If you have already installed in ${OPENHAB_HOME}/addons folder, remove binding from there first.

Bridge

A Simatic Bridge is needed to connect to PLC. It provides exactly one communication channel to single PLC.

Basic bridge configuration requires to know PLC address, rack and slot. Additional parameters can be defined.

Parameter Required Notes
address Yes Network IP/Host address of PLC.
rack Yes The rack number in which CPU is presented.
slot Yes The slot number where CPU is inserted.
pollRate No Read period [ms]. Default is 1000ms.
charset No Define code page for communicated strings (e.g. ISO-8859-1, cp1250). If blank or wrong code page is defined, system code page is used. Used code page is printed into log file as INFO.
communicationType No Type of communication that should be established. Possibilities are PG, OP, S7 (default).
isS7200 No Communication partner is CP243 (Simatic S7-200).
updateMode No Update mode of the Channel State to the openHAB framework. It can be OnChange (only the changes are updated - default) or Poll (everything read from PLC are updated).

Bridge definition together with things can be defined in text files. See generic bridge configuration for details. In short text files .things are located in ${OPENHAB_CONF}/things folder. Basic bridge configuration with required parameters looks like this:

Bridge simatic:bridge:<plc_id> "Label" @ "Location" [ address="<host/ip address>", rack="<rack>", slot="<slot>" ]

Example with optional parameter:

Bridge simatic:bridge:S7-416 "My PLC"  [ address="192.168.1.36", rack="0", slot="2", charset="ISO-8859-1" ]

Things

To any individual bridge things could be added. Things are user defined so only generic_device thing is available.

Things definition can be defined in text files. Easiest way is to put it inside bridge definition:

Bridge simatic:bridge:<plc_id> "Label" @ "Location" [ address="<host/ip address>", rack="<rack>", slot="<slot>" ] {
    Thing generic_device <thing_id> "Thing label" {            
    }
}

Channels

For generic_device thing binding supports channels types listed in the table below. Individual channel type are converted to simple data types such as bit, byte, word, double word, float, array.

Channel type Simatic data type Address example Notes
chNumber bit, byte, word, dword, float IB0, E0.0, MW5, MD10, DB1.DBD4F Numbers are represent in signed form. Their maximum value depends on the used type.
Floating point number is stored in 4 bytes formatted according to IEEE 754. PLC address for float must be specified as DWORD with 'F' sign at the end of address.
Extra parameter unit can be specified (since 3.0.5). To push unit into the item number with dimension must be defined.
chColor dword MD100, DB1.DBD20 All color parts are transferred in one double word. Each color component corresponds to one byte. Bytes assignment:
RGB - byte 0 - Red, 1 - Green, 2 - Blue, 3 - Not used
chString byte array MB100[32], DB1.DBB0[20] Array of bytes represent null terminated string. Length of array is specified in square brackets behind type definition (e.g. MB100[32] defines byte array at address MB100 with length 32 bytes)
chContact bit, byte IB0, MB10.0, DB1.DBX0.0 0 - off, 1 - on
chSwitch bit, byte IB0, MB10.0, DB1.DBX0.0 0 - off, 1 - on
chDimmer byte MB100, DB1.DBB10 Value range is 0-100
chRollershutter byte MB5 State specifies position (0-100%). Command sends Stop/Up/Down (2-Stop, 4-Up, 8-Down).

Every channel has two parameters stateAddress and commandAddress. At least one must have a defined value. Number item has extra parameter unit. Supported PLC areas are inputs I(E), outputs Q(A), memory M and datablocks DB. Symbolic addressing is not supported.

Channel text file definition as part of thing:

Bridge simatic:bridge:<plc_id> "Label" @ "Location" [ address="<host/ip address>", rack="<rack>", slot="<slot>" ] {
    Thing generic_device <thing_id> "Thing label" {
        Channels:
            Type <channel_type> : <channel_id> [ stateAddress="<simatic address>", commandAddress="<simatic address>" ]
    }
}

Configuration example

Bridge simatic:bridge:S7-416 "My PLC"  [ address="192.168.1.36", rack="0", slot="2", charset="ISO-8859-1" ] {
    Thing generic_device plcState "PLC state" {
        Channels:
            Type chNumber: watchdog [ stateAddress="MB0" ]
    }
    Thing generic_device weather "Weather station" {
        Channels:
            Type chNumber: temperature [ stateAddress="DB1.DBD0F", unit="°C" ]                
            Type chNumber: pressure [ stateAddress="DB1.DBW4", unit="Pa" ]
            Type chNumber: humidity [ stateAddress="DB1.DBB6", unit="%" ]
    }
    Thing generic_device hall "Hall" {
        Channels:
            Type chContact: door_contact [ stateAddress="I0.0" ]                
            Type chSwitch: light_switch [ stateAddress="M5.1", commandAddress="M5.1" ]
            Type chString: humidity [ stateAddress="DB1.DBB6" ]
    }
    Thing generic_device device "Special device" {
        Channels:
            Type chSwitch: run  [ stateAddress="DB10.DBX0.0", commandAddress="DB10.DBX0.1" ]            
            Type chDimmer: rate [ stateAddress="DB10.DBB1", commandAddress="DB10.DBB2" ]
            Type chString: text [ stateAddress="DB10.DBB3[20]", commandAddress="DB10.DBB3[20]" ]
    }
}
Bridge simatic:bridge:S7-1210 "My second PLC"  [ address="192.168.1.37", rack="0", slot="1" ] {
    Thing generic_device rollers "Rollershutters" {
        Channels:
            Type chRollershutter: rs1 [ stateAddress="MB100", commandAddress="MB101" ]            
            Type chRollershutter: rs2 [ stateAddress="MB102", commandAddress="MB103" ]
    }
}

Optimisation

For large systems slow response can be observed. Generally it is caused by non-optimised configuration.

At design time it important to remember to optimise transferred data. Ideal layout is put all data into one data area (datablock) one by one without any gaps. That's because data from PLC are read in blocks. Maximum block size depends by negotiated PDU size. Current PDU size is available as bridge channel or is printed in openHAB log file. Standard PDU size by PLC:

PLC family PDU size [byte]
S7-300 240
S7-400 480
S7-1200 240
S7-1500 960

If data length is greater than PDU size limit, another block read is established.

Similarly with gaps (unused data parts). If gap between configured data if greater then 32 bytes, new block read is established. Gaps smaller than 32 bytes means less read from PLC.

Overview about read areas or read requests per second are available in binding. Look at bridge channels.

Clone this wiki locally