IMDHMIControls LibraryShop main store

Troubleshooting

Troubleshooting an S7-1500 OPC UA client that cannot connect

Industrial networks Published 8 min read

Short answer

Behind a router, an S7-1500 OPC UA client block cannot connect because the productive connection follows the endpoint URL the server advertises at discovery, an address unreachable from the PLC's side. Copy the exact opc.tcp URL from the connection DB into the ServerUri field, download and restart the PLC. That combination cleared the reported failure, and a startup capture proves the cause in one pass.

On this page
  1. Why does the PLC fail behind a router when a PC client connects?
  2. Which hop fails when the block reports it cannot connect?
  3. How do I prove the advertised endpoint is the cause?
  4. How do I set the server URI so the PLC connects through the router?
  5. What does the fix look like with real addresses?
  6. What confirms the connection is fixed?
  7. Which mistakes keep the connection down?
  8. Which fix applies to which symptom?
  9. Questions asked

An S7-1500 OPC UA client block that reports it cannot connect to a third-party server — while a PC client reads that same server, and one or more routers sit between — is following the server's advertised endpoint URL to an address unreachable from the PLC's side. The fix is short: copy the endpoint URL exactly as it stands in the connection DB into the ServerUri field, download, and restart the PLC. That combination cleared a reported installation with these exact symptoms, where the target variables were even visible through the TIA Portal online interface while the read block stayed down.

Why does the PLC fail behind a router when a PC client connects? #

The S7-1500 OPC UA client builds its connection in two stages — a discovery connection first, then the productive connection — and the productive connection targets the endpoint URL the server advertises, not the address you configured. OPC UA Part 4 defines discovery as its own step and lists a well-known discovery address of the form opc.tcp://localhost:4840/UADiscovery; the server answers the request with endpoint URLs built from the hostname or address it knows for itself.

On one subnet the advertised address and the reachable address are the same, which is why a client configuration that reads a server on the local network looks correct. Put a router or a NAT device in the path and the two split: the PLC's discovery request travels to the address you configured and succeeds, then its session request follows the advertised URL and dies. A PC client that keeps the URL it was given keeps working — that is the split you see between the two clients. Setting the advertised hostname to the translated address is the server-side counterpart, covered in configuring OPC UA endpoint URL hostnames behind NAT.

The same mechanism runs in reverse when the S7-1500 is the server and SCADA is the client across a translated address; connecting an S7-1500 to SCADA over OPC UA from TIA Portal covers that direction.

Which hop fails when the block reports it cannot connect? #

A cannot-connect status means the failure sits before any read: work the six hops below in order and stop at the first one that fails, because node IDs, namespace indexes and access rights cannot affect anything until a session is open.

  • Link — PLC to the first router, last router to the server's network. A PC client on the PLC's subnet reaching the server clears this hop and the next one at once.
  • IP routing — the routers forward packets between the subnets; cleared by the same PC test.
  • TCP connection to the server's port — 4840 is the OPC UA default, but the port the server publishes governs, and it stands in the URL the connection DB holds; a wrong or blocked port gives the same status as a wrong address.
  • Discovery — the client fetches the endpoint list. Across routers this hop still succeeds, because it uses the address you configured.
  • Secure channel and session — opened on the endpoint the client selected. Behind a router this is the hop that dies, on the advertised address.
  • Read and write services — node IDs resolved, values returned. Reachable only once the session is up; skip until the status reports connected.

How do I prove the advertised endpoint is the cause? #

Two checks decide it in one pass: read one target node with a PC client from the PLC's own subnet, then capture the PLC's startup with Wireshark and compare the destination of the first TCP SYN with the destination of the connection that follows discovery.

Run the baseline first, with a PC client such as UA Expert on the PLC's network segment. If that client cannot connect either, the fault is routing, NAT or a firewall, and the ServerUri change will not help — repair the path first. If it reads the node, the server, its security settings and node access are all good, and the fault lies in what the PLC does with the endpoint list.

Capture next, from a mirror port or a tap on the PLC's switch, starting before the CPU restarts so the whole connect sequence is recorded. Read the SYNs in order: the first travels to the address in the connection DB and is answered; the second travels to a different address and gets no reply. That second address is the advertised endpoint, and seeing it ends the diagnosis.

How do I set the server URI so the PLC connects through the router? #

Copy the endpoint URL from the connection DB configuration into the ServerUri field at Connection > ConnectInfo, character for character, then download and restart the PLC — the changed URI is only read when the connection is established again.

  1. Open the connection DB in TIA Portal and read the URL its configuration holds, in the form opc.tcp://<address>:<port> — for example opc.tcp://192.168.1.10:4840. Note whether it carries a hostname or an IPv4 address, and note the port.
  2. Copy that exact string into ServerUri under Connection > ConnectInfo in the DB the connect logic reads. Copy, do not retype: a hostname swapped for an IP, or a dropped port, reproduces the failure.
  3. If the URL holds a hostname, the PLC must resolve it from its own interface settings; OPC UA connections that depend on advertised hostnames resolving in DNS covers that side, and the IPv4 form bypasses name resolution entirely.
  4. Confirm the router forwards that port to the server and that no firewall rule blocks it from the PLC's subnet.
  5. Download the change and restart the CPU. Schedule the restart for a production stop: the CPU goes to STOP and the machine it controls stops with it.
  6. Watch the connect block's status: it must leave the cannot-connect state and report connected before any read is judged. The program-side sequence is covered in starting an OPC UA client connection from PLC code.

What does the fix look like with real addresses? #

In this worked example the PLC sits at 192.168.1.50 with mask 255.255.255.0, the router at 192.168.1.1 forwards 192.168.1.10 to a server at 10.1.10.20, and the server advertises opc.tcp://10.1.10.20:4840. The example assumes the router exposes only the mapped address — the usual port-forwarding arrangement — and does not route the PLC's subnet onto the server's private network.

Connection Destination Subnet arithmetic Result
Discovery 192.168.1.10:4840, the address in the connection DB 192.168.1.10 AND 255.255.255.0 = 192.168.1.0, equal to the PLC's own 192.168.1.50 AND 255.255.255.0 = 192.168.1.0 Sent on the local link and answered; the router translates it to the server
Session before the fix opc.tcp://10.1.10.20:4840, the advertised endpoint 10.1.10.20 AND 255.255.255.0 = 10.1.10.0, not the PLC's subnet Sent to the default gateway 192.168.1.1; nothing answers; the block reports it cannot connect
Session after the fix opc.tcp://192.168.1.10:4840 in ServerUri Same subnet as the discovery request Answered through the router's translation; the session opens and reads return values

One capture tells the whole story: a SYN to the mapped address answered, a SYN to the advertised address unanswered, and after the change a single session on the mapped address.

What confirms the connection is fixed? #

Call it fixed when the connect block holds a connected status, a read returns the same value a PC client shows for the same node at the same moment, and a power cycle brings the connection back with no further edits.

  • The status holds connected across cycles, not a transient pass that drops again.
  • The read value matches the PC client's value for the same node.
  • A repeat capture at startup shows one session to the mapped address and port, with no second SYN to the advertised address.
  • One more power cycle: the connection re-establishes with no edits to the DB.

Which mistakes keep the connection down? #

Five mistakes account for nearly every repeat call: editing the URI without restarting, retyping instead of copying the URL, judging success by the variables showing in the TIA Portal online interface, testing only from the server's subnet, and chasing node IDs while the status still says it cannot connect.

Mistake Effect Correction
Editing the URI without restarting The connection keeps the parameters it was established with; the status never changes Download, then restart — the restart is part of the fix
Retyping the URL instead of copying it One character of difference and the session still aims at the wrong target Copy the string from the DB configuration
Judging success by the online interface showing the variables Online visibility proves the engineering path, not the client session; the read block can still fail Judge by the connect block status and a returned value
Testing only from a PC on the server's subnet The test hides the routed path the PLC actually uses Run the PC baseline from the PLC's segment
Chasing node IDs while the status says it cannot connect Time spent on a stage the client never reaches Clear the connection first, then verify node IDs

Which fix applies to which symptom? #

Match the symptom to one of four cases: a PC on the PLC's subnet reading while the PLC cannot points at the advertised endpoint and gets the ServerUri fix, and each of the other three has its own different fix.

Symptom Cause Fix
A PC on the PLC's subnet reads the server; the PLC block cannot connect; routers in the path The advertised endpoint is unreachable from the PLC's side Copy the DB's endpoint URL into ServerUri, download, restart
No client from the PLC's subnet reaches the server Routing, NAT or a firewall, not the endpoint URL Correct the route or port forwarding first; the ServerUri change cannot help
The block connects, but reads return nothing Read stage: wrong namespace index or node ID in the read list Compare the node ID and namespace index against what the PC client browses
Good after the restart, gone again after the next power cycle The corrected URI is not in the downloaded DB, or was retyped with a difference Copy the string again, download, restart, then power-cycle to prove it returns

The reported installation with the first symptom set — variables visible online, a PC client reading, the block unable to connect, routers in the path — was cleared by the first row alone, with no change to the server.

Questions asked

Can I correct the advertised address on the server instead of the PLC?

Yes. Configuring the server to advertise the translated address, or a hostname that resolves to it, fixes every client behind the router at once, with no change on the PLC. Choose the server-side fix when several clients sit on the PLC's side of the router; choose the ServerUri fix when the server belongs to a machine builder whose configuration you cannot change, as in the reported case.

Will a hostname work in the server URI?

Only if the PLC can resolve that name through its own interface settings. A name the CPU cannot resolve reproduces the cannot-connect status even when the address and port behind it are right, so on a machine network with no name server, use the IPv4 address form of the URL instead.

Would moving the PLC onto the server's subnet avoid the problem?

Yes. With no router in the path the advertised address is reachable by construction, so the unchanged configuration connects. The move costs a cable run and a new address, and it removes the routed segment the cell was built around, so treat it as a one-time proof when a capture is impossible, not as the repair.

Why does the block report a generic cannot-connect status instead of the cause?

The connect block reports the stage, not the reason. A session that gets no TCP answer ends in the same status as a wrong port or a blocked firewall, because from inside the client they all look like a session that never opened. Read the status as a failure before the read stage and go straight to the two checks, the PC baseline and the startup capture.

Keep reading

  • Troubleshooting

    Connecting Factory I/O to a local CODESYS soft PLC over OPC UA

    Yes: OPC UA only carries tag values, so the ladder or structured text must run in the CODESYS runtime. Fix the connection in order: prove the engineering path through the Gateway to the runtime first, then the OPC UA endpoint at port 4840, then map each scene point to one variable. Keep Control I/O out of it, because Factory I/O runs one driver at a time.

    Industrial networks

  • Troubleshooting

    Fix robot Profinet output writes over OPC UA

    Set the Profinet Internal Device Input Size and Output Size to 64 bytes each, under Controller tab, Configuration, I/O System, Profinet Internal Device, and robot output writes reach the PLC array. The failing direction, not the OPC UA status number, identifies the cause: a Bad-class write with the other direction working means the output byte image is missing.

    Industrial networks

  • How-to

    Connect an S7-1500 to SCADA over OPC UA from TIA Portal

    The S7-1500 has a built-in OPC UA server from firmware V2.0, deactivated by default. Enable it in the CPU device properties in TIA Portal, select the installed server license, copy the endpoint URL, and download. Paste the opc.tcp address into any OPC UA SCADA client, trust the certificates on both sides, then browse the PLC variables and map them to SCADA tags.

    SCADA and data logging