Node-RED Siemens S7 PLC Communication
node-red-contrib-s7comm is a Node-RED package designed to facilitate communication with Siemens SIMATIC S7-300, S7-1200, and S7-1500 PLCs. It leverages the RFC1006 (ISO-on-TCP) communication protocol, enabling users to read from and write to specific PLC addresses using various S7 data types. The current stable version is 1.1.6. As a Node-RED contribution node, its release cadence is typically driven by community contributions and updates to its underlying `nodeS7` library, which handles the core PLC communication. Key differentiators include its integration into the Node-RED flow-based programming environment, simplifying the creation of HMI, SCADA, or IIoT applications that interact with Siemens PLCs without requiring extensive low-level protocol knowledge. It abstracts the complexities of the S7comm protocol behind user-friendly Node-RED nodes.
Common errors
-
Error: Connection refused
cause The PLC rejected the connection attempt, often due to incorrect IP, port, firewall blocking, or PLC security settings.fixVerify the PLC's IP address and port (default 102), check network connectivity between Node-RED host and PLC, ensure no firewall is blocking port 102, and confirm PLC 'Protection & Security' settings allow PUT/GET communication. -
Error: S7 response data error - wrong data size
cause The configured data length or type in the Node-RED node does not match the actual data block/variable size on the PLC.fixIn the Node-RED node's configuration, precisely match the S7 data type (e.g., INT, REAL) and length to what is defined in the TIA Portal for the target PLC address (DB, address, size). -
Error: S7 PLC response: 10/FF00
cause Generic PLC communication error, frequently indicating that the PLC's security settings prevent access to the requested data block or an unsupported access method.fixCheck the PLC's 'Protection & Security' settings in TIA Portal for PUT/GET permissions. For data blocks, ensure 'Optimized block access' is not solely enabled if the client expects standard access, or vice-versa, and verify block attributes. -
TypeError: Cannot read properties of undefined (reading 'config')
cause This error typically occurs within Node-RED when a node's associated configuration node (e.g., the S7comm-Config node) is either missing, unlinked, or not properly deployed.fixEnsure that your 's7comm read' or 's7comm write' node is correctly linked to an 's7comm-config' node, and that the 's7comm-config' node is also properly configured. Perform a 'Full deploy' in Node-RED after making changes.
Warnings
- gotcha Siemens S7-1200/1500 PLCs require specific 'Protection & Security' settings in TIA Portal (e.g., 'Permit access with PUT/GET communication from remote partner') to allow external read/write access via S7comm. Failure to configure this will result in connection refusal.
- gotcha Incorrect S7 data type or length configuration in the Node-RED node can lead to read/write errors, corrupted data, or unexpected values. The node expects precise mapping to the PLC's actual data block structure.
- gotcha Node-RED flow deployments, especially involving configuration nodes, must be handled carefully. Partial or incorrect deployments can result in nodes remaining uninitialized or losing their connection settings.
- gotcha The stability and security of `node-red-contrib-s7comm` are dependent on the underlying `nodeS7` library. Any vulnerabilities or critical bugs discovered in `nodeS7` will directly impact this Node-RED contribution.
Install
-
npm install node-red-contrib-s7comm -
yarn add node-red-contrib-s7comm -
pnpm add node-red-contrib-s7comm
Imports
- S7CommNode
/* This package is a Node-RED node. Users do not typically import symbols directly into JavaScript. */
- S7ConfigNode
/* This package is a Node-RED node. Users do not typically import symbols directly into JavaScript. */
- S7Client
/* This package is a Node-RED node. Users do not typically import symbols directly into JavaScript. */
Quickstart
// To install the Node-RED node:
// 1. Ensure Node-RED is installed and running.
// 2. Open the Node-RED editor (usually http://localhost:1880).
// 3. Go to the Palette Manager (top-right menu -> Manage palette).
// 4. In the 'Install' tab, search for 'node-red-contrib-s7comm' and click install.
// After installation, drag 's7comm read' and 's7comm write' nodes from the palette onto your flow.
// Example JavaScript code showing conceptual S7 client usage, not direct 'node-red-contrib-s7comm' usage:
// import { S7Client } from 'nodeS7'; // Hypothetical import if using nodeS7 directly
// async function readS7Data() {
// const client = new S7Client();
// try {
// await client.connect({
// host: '192.168.0.1',
// port: 102,
// rack: 0,
// slot: 1
// });
// console.log('Connected to PLC.');
// const data = await client.readArea(
// S7Client.S7Area.DB,
// 1, // DB number
// 0, // Start offset
// 2, // Length (e.g., 2 bytes)
// S7Client.S7Type.WORD
// );
// console.log('Read data:', data);
// } catch (error) {
// console.error('S7 communication error:', error);
// } finally {
// client.destroy();
// }
// }
// readS7Data();