S7-1500 OPC UA Server: Resolving ECONNREFUSED Errors

David Krause11 min read
OPC / OPC UASiemensTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Problem Overview: OPC UA Connection Refused on S7-1500

An OPC UA client (in this case, Node-RED running on a SIMATIC IoT2020) attempts to open a session to an S7-1500 OPC UA server and receives:

OPC UA connection error: connect ECONNREFUSED 192.168.178.100:4840

The error string ECONNREFUSED is a standard POSIX/Winsock socket status returned by the underlying TCP transport when no application is listening on the target IP/port combination, or when a host firewall drops the SYN. In the OPC UA stack, the client maps this to Bad_CommunicationError or BadConnectionClosed before the secure channel is even established. Unlike certificate trust errors (which surface as BadCertificateUntrusted), ECONNREFUSED means the TCP three-way handshake never completed against a listening server endpoint.

For a SIMATIC S7-1500, this is almost always caused by one of the following conditions:

  1. The OPC UA server is not enabled in the PLC's security configuration.
  2. The required OPC UA runtime license is missing (firmware V2.6 and later require a separate runtime license on many CPU variants).
  3. The IP address of the PLC or client is on a different subnet and no default gateway routes between them.
  4. A Windows firewall or PLC-side security policy blocks inbound TCP/4840.
  5. The PLC's project is not compiled and downloaded, or the device configuration is in a STOP / inconsistent state.

Affected Hardware, Firmware, and Software Versions

Component Version Tested Notes
S7-1500 CPU (e.g., CPU 1515-2 PN) Firmware V2.6.x and V2.9.x OPC UA server availability depends on firmware; see product manual for specific CPU
TIA Portal V16 / V17 / V18 Configuration tree path differs slightly between versions
SIMATIC IoT2020 Image V2.6 (Debian 9) and V3.x (Debian 10) Node-RED ships pre-installed on most images
node-red-contrib-opcua v0.2.324 and later Node-RED v2.x or v3.x
UaExpert (test client) 1.7.1 and later OPC Foundation official test client

Always confirm against the specific CPU's product manual and the corresponding TIA Portal release notes, since the OPC UA feature set and license model have been revised multiple times.

Reference Architecture

The deployment described uses three logical layers:

  • OPC UA Server: SIMATIC S7-1500 (192.168.178.100) running the built-in OPC UA server interface.
  • OPC UA Client: Node-RED running on a SIMATIC IoT2020 (192.168.178.29) using node-red-contrib-opcua.
  • Diagnostic Client: UaExpert running on an engineering station, used to verify server reachability independent of the IoT2020.

All three devices must share a routable L2/L3 path. The Node-RED flows for this application are intentionally minimal: a single opcua-Client node is configured with the endpoint URL opc.tcp://192.168.178.100:4840 and pointed at a data block using its NodeId, e.g. ns=3;s="DB_HMI"."HMI_Tag".

Root Cause Analysis: Why ECONNREFUSED Occurs

Working from the lowest layer up:

Layer 1 — Physical / Data Link

Verify link LEDs on the PLC PROFINET port and the IoT2020 Ethernet port. A green link LED on both devices eliminates a cabling or switchport issue. If the IoT2020 is connected through a managed switch, confirm the port is enabled and not in a disabled VLAN.

Layer 2/3 — IPv4 Routing

From the IoT2020 shell, run ping 192.168.178.100. A successful ICMP echo reply confirms ARP resolution and routing. A "Destination Host Unreachable" reply indicates either a local subnet mismatch or a missing default gateway. From Windows, run Test-NetConnection 192.168.178.100 -Port 4840 to verify the TCP port is open — this test isolates port reachability from full OPC UA session negotiation.

Layer 4 — TCP Listener

If ICMP succeeds but TCP/4840 returns ECONNREFUSED, the most likely causes are:

  • OPC UA server not enabled in TIA Portal under Device configuration → Properties → OPC UA → Server.
  • Missing OPC UA license on the CPU — older CPU variants include OPC UA in the basic firmware, but newer firmware versions (V2.6+) require the optional "OPC UA Server" runtime license activated in the PLC's Web server / License management page.
  • PLC in STOP — the OPC UA server only accepts connections when the CPU is in RUN.

Layer 7 — OPC UA Security / Trust

If the server is reachable at the TCP level but the session terminates with a BadCertificateUntrusted error, the issue is a certificate trust problem — not an ECONNREFUSED error. Distinguishing the two is critical: a trust problem requires accepting the client certificate on the PLC, while a connection refusal requires server activation or a firewall fix.

Step-by-Step Resolution Procedure

Step 1 — Confirm Server Is Listening on Port 4840

From the engineering station, run a TCP probe to confirm the server is bound to the expected endpoint:

Test-NetConnection 192.168.178.100 -Port 4840

A TcpTestSucceeded : True response confirms the server is alive. A False response, or a Linux telnet 192.168.178.100 4840 returning Connection refused, confirms the server is not listening.

Step 2 — Activate the OPC UA Server in TIA Portal

  1. Open the TIA Portal project containing the S7-1500 station.
  2. Select the CPU in the project tree and open Properties.
  3. Navigate to OPC UA → Server.
  4. Check Activate OPC UA server.
  5. Set the desired port (default 4840).
  6. Configure security policies. For commissioning, select None and Sign & Encrypt / Sign as needed, or start with None to isolate the problem.
  7. Compile (hardware rebuild) and download to the PLC.
  8. Cycle the CPU to RUN if it was in STOP.

Refer to the Siemens SIMATIC S7-1500 OPC UA Server Function Manual for CPU-specific details, and to the TIA Portal help under "Configuring the OPC UA server" for the full property set.

Step 3 — Verify the OPC UA License

On firmware V2.6 and later, confirm the license is present:

  1. Open the PLC's Web server (http://192.168.178.100) and log in as administrator.
  2. Navigate to License management.
  3. Verify that the OPC UA Server license entry is present and active.

If the license is missing, the CPU may still bring up the server socket in some firmware versions, but it will refuse client sessions immediately. Older CPU variants (e.g., CPU 1511/1513 with firmware V1.x) included the OPC UA server without a separate license — verify against the specific CPU's manual.

Step 4 — Validate with UaExpert

Before changing the Node-RED flow, validate the server with the official OPC Foundation test client:

  1. Install UaExpert from the OPC Foundation download page.
  2. Add a new server connection: opc.tcp://192.168.178.100:4840.
  3. Select the endpoint matching the security policy you configured in TIA Portal.
  4. Click Connect.

If UaExpert connects and browses the address space, the server is healthy. If it fails with a trust error, accept the certificate in UaExpert's Certificate Manager and reconnect. This isolates whether the problem is server-side or client-side.

Step 5 — Configure Node-RED OPC UA Client

The IoT2020 (Debian) uses node-red-contrib-opcua. Configure the client endpoint:

opc.tcp://192.168.178.100:4840

For a minimal commissioning flow that exercises a single DB tag:

[
  {
    "id": "opcuaClient1",
    "type": "opcua-Client",
    "z": "flow1",
    "endpoint": "opc.tcp://192.168.178.100:4840",
    "securityPolicy": "None",
    "securityMode": "None",
    "name": "",
    "x": 320,
    "y": 180,
    "wires": [[]]
  }
]

Use the Action set to Subscribe or Read with the NodeId ns=3;s="DB_HMI"."HMI_Tag" for the initial test. The namespace 3 is the standard for S7-1500 data blocks. Always confirm by browsing the address space in UaExpert first.

Step 6 — Manage Client Certificates

Once a non-None security policy is enabled, the PLC will reject the Node-RED client until its certificate is trusted. There are two paths:

  • Trust the client in TIA Portal: Under Device configuration → Properties → OPC UA → Security → Trusted clients, add the IoT2020 client certificate, then download the project to the PLC.
  • Use "Automatically accept client certificates" for testing only. Disable in production.

The PLC's OPC UA server → Security → Certificate store page in the Web server allows you to inspect and remove untrusted client certificates.

Verification Checklist

Check Expected Result Verification Command / Method
Link LEDs on PLC and IoT2020 Both green Visual inspection
ICMP from IoT2020 to PLC Reply from 192.168.178.100 ping 192.168.178.100
TCP/4840 reachable Port open Test-NetConnection 192.168.178.100 -Port 4840 or nc -zv 192.168.178.100 4840
OPC UA server activated in TIA Portal Checkbox enabled, project downloaded TIA Portal online diagnostics
OPC UA license License present and active PLC Web server → License management
UaExpert connects Session established, address space browses UaExpert UI
Node-RED flow status opcua-Client node shows connected Node-RED debug sidebar / status indicator

Fault Code and Error Reference

Observed Symptom Underlying Cause Resolution
ECONNREFUSED on TCP/4840 OPC UA server disabled, missing license, CPU in STOP, firewall Enable server in TIA, verify license, run CPU, open firewall
ECONNREFUSED intermittent CPU in STOP from fault; license timeout Clear PLC fault buffer; check license validity
BadConnectionClosed Session killed after trust rejection Trust client certificate in TIA Portal
BadCertificateUntrusted PLC does not trust client cert Add client cert to Trusted clients and download project
BadIdentityTokenRejected Wrong username/password or anonymous disabled Match credentials in Authentication settings of TIA
BadSecurityChecksFailed Mismatched security policy between client and server Align security policy in Node-RED and TIA Portal
UaExpert connects, Node-RED does not Node-RED client cert untrusted Add Node-RED client cert to PLC trusted list

Troubleshooting Matrix

Symptom Most Likely Cause First Action
ECONNREFUSED, PLC reachable via ping Server disabled or no license Re-check TIA Portal → OPC UA → Server
ECONNREFUSED, PLC not reachable IP/subnet mismatch or VLAN issue Verify both devices in 192.168.178.0/24
TCP/4840 open, OPC UA fails with cert error Certificate trust Add client cert to PLC trusted list
TCP/4840 open, OPC UA fails with security error Policy mismatch Match security policy/None in both client and server
Server worked yesterday, fails today PLC STOP, license expired, or firewall push Check PLC diagnostic buffer and license status

Common Pitfalls and Field-Validated Caveats

Pitfall 1 — Different security policies on different endpoints. The S7-1500 advertises multiple endpoints (None, Basic128Rsa15, Basic256Sha256, Aes128Sha256RsaOaep). The client must pick one of the enabled ones. If Node-RED is set to None but TIA Portal has only Sign & Encrypt enabled, the connection will be refused at the secure-channel layer. Always confirm with UaExpert first — it shows the available endpoints.
Pitfall 2 — Project not downloaded after configuration change. Enabling the OPC UA server in TIA Portal has no effect on the running CPU until the project is compiled and downloaded. Verify with the online diagnostics view that the server is actually running.
Pitfall 3 — Firewall on the engineering station. When running UaExpert on a Windows host, the local Windows firewall may block outbound TCP/4840 to the PLC. Allow the application or open the port for the test.
Pitfall 4 — VLAN mismatch on managed switches. A S7-1500 PROFINET port and the IoT2020 must be on the same VLAN, or routed by a Layer 3 device. A managed switch that places the PLC in VLAN 10 and the IoT2020 in VLAN 20 will silently drop frames, producing the same ECONNREFUSED symptom.
Pitfall 5 — IP address bound to wrong PROFINET interface. On a S7-1500 with two PROFINET ports (e.g., CPU 1515-2 PN), confirm that 192.168.178.100 is bound to the port the engineering switch is connected to. The OPC UA server listens on the IP address of the configured interface, not on all addresses.

Alternate Platforms and Controllers

The same diagnostic logic applies to other Siemens controllers that ship an OPC UA server. Differences in the configuration tree are minor:

  • S7-1200 (firmware V4.4 and later): OPC UA server is opt-in under Device configuration → OPC UA. License handling is identical.
  • ET 200SP CPU: Same as S7-1500; the OPC UA server is in Properties → OPC UA → Server.
  • SIMATIC S7-1500 Software Controller (WinAC RTX / S7-1507S): Requires the OPC UA server feature to be activated in the same TIA Portal project tree path.

For non-Siemens controllers, consult the vendor's OPC UA server documentation for the specific activation steps; the underlying TCP/4840 reachability checks remain identical.

FAQ

Why does the S7-1500 return ECONNREFUSED on port 4840 even when the CPU is in RUN?

The OPC UA server is disabled by default in many TIA Portal projects. Open Device configuration → Properties → OPC UA → Server, enable the checkbox, compile, and download the project. On firmware V2.6 and later, also confirm the optional OPC UA license is active in the CPU's Web server under License management.

Does the IoT2020 Node-RED OPC UA client need a license?

No. The OPC UA client side is implemented in the open-source node-opcua library used by node-red-contrib-opcua and has no runtime license requirement. The license applies only to the OPC UA server on the S7-1500 side.

How do I accept the IoT2020 client certificate on the S7-1500?

In TIA Portal, open the CPU's Properties → OPC UA → Security → Trusted clients, add the IoT2020 client certificate, compile, and download the project to the PLC. Alternatively, for testing only, enable Automatically accept client certificates in the same dialog and disable it for production.

What is the default OPC UA port on a S7-1500?

The default port is 4840/tcp for the unencrypted endpoint and 4840/tcp for the encrypted endpoints (the port is shared; security is negotiated on the OPC UA layer). The port can be changed in TIA Portal under OPC UA → Server → Port; if changed, both the client endpoint URL and any firewall rules must be updated.

Can the S7-1500 OPC UA server run with security set to None?

Yes, but only for commissioning and bench testing. The None security policy disables encryption and authentication and must be disabled in production deployments. Enable at least Sign and use a unique application certificate per device, managed through the PLC's certificate store.

Back to blog