IMDHMIControls LibraryShop main store

Troubleshooting

OPC UA BadCommunicationError after download to the PLC

SCADA and data logging Published 7 min read

Short answer

After a download, an OPC UA data source runs in the PLC, so localhost in the endpoint URL points at the controller instead of your engineering PC. Replace it with the server computer's PLC-routable IP address, confirm client and server share one advertised security policy, then complete certificate trust on both sides.

On this page
  1. Why does the data source work in the IDE but fail after the download?
  2. What does localhost mean once the data source runs in the PLC?
  3. How do you confirm the PLC can reach the server computer?
  4. Which endpoint URL should the downloaded data source carry?
  5. Why does a corrected endpoint still fail with BadCommunicationError?
  6. Which security policy can the PLC runtime actually use?
  7. What is the fix procedure that verifies the connection end to end?
  8. Questions asked

An OPC UA data source that browses fine from the engineering PC and then throws BadCommunicationError the moment you download is almost always pointing at localhost. In the IDE the request leaves your PC; after the download it leaves the PLC, and the PLC's localhost is the controller itself. Replace localhost in the endpoint URL with the server computer's PLC-routable IP address. In the reported case, on CODESYS 3.5 SP19 Patch 7, one address change restored the network path, and a second, separate fix — a security-policy intersection — restored the session. This article walks both branches in the order you meet them.

Why does the data source work in the IDE but fail after the download? #

Because the requester changes: during configuration the OPC UA call leaves your engineering PC, so localhost in the endpoint URL reaches the server on that same PC, while after the download the call leaves the PLC, and the PLC's localhost is the controller itself. The data source connection object executes wherever its owning code runs, and download moves that execution from the IDE to the runtime.

Phase Where the request originates What localhost resolves to Result
Configure and browse Engineering PC The PC itself Browse succeeds
Downloaded data source PLC runtime The PLC's loopback BadCommunicationError
Runtime with server IP PLC runtime The server computer Network path opens

The same origin rule applies to any client the controller starts itself: a setup that begins an OPC UA client connection from PLC code negotiates and transmits on the PLC's network stack, never the PC's, so testing it from the PC repeats the same false positive.

What does localhost mean once the data source runs in the PLC? #

Once the data source executes in the runtime, localhost resolves to the controller's own loopback interface, address 127.0.0.1, so a request to an endpoint such as opc.tcp://localhost:4840 never leaves the controller and fails before any cable is touched. The endpoint's host portion has to name the machine running the OPC UA server as seen from the PLC's routing context.

The one legitimate localhost case is an OPC UA server running inside the same PLC: then the client and server share the controller, and the loopback is correct. For a server on a separate computer, an engineering station, or a gateway box, localhost in the downloaded application is always wrong.

How do you confirm the PLC can reach the server computer? #

Confirm the physical link and the IP path before touching OPC UA settings: check the PLC's Ethernet link LEDs and switch port, then verify the PLC and the server computer sit in the same subnet or have a gateway between them that permits TCP on the endpoint port. Work down this list:

  • Link state: PLC Ethernet LEDs on, switch port up, no growing physical error counters on the interface.
  • Addressing: PLC address, subnet mask and default gateway noted against the server computer's active interface.
  • Path: reachability tested from a device on the PLC's own network segment, because a test run on the server computer can pass for the same reason localhost passed.
  • Transport: the server actually listening, and the endpoint port permitted through any firewall between the two subnets.

Worked example. The PLC has 192.168.1.20 with subnet mask 255.255.255.0 and the server PC has 192.168.1.50. The network portion of 192.168.1.20 ANDed with 255.255.255.0 is 192.168.1.0, and 192.168.1.50 ANDed with 255.255.255.0 is also 192.168.1.0, so both addresses sit in one subnet and no gateway is involved. Move the server to 192.168.2.50 and its network becomes 192.168.2.0: traffic now crosses a gateway — for example 192.168.1.1 — and that router and any firewall in between must permit TCP to the endpoint port. Port 4840 is the common OPC UA default, but read the actual port from the server's endpoint configuration instead of assuming it.

Which endpoint URL should the downloaded data source carry? #

The downloaded data source must carry an endpoint URL whose host portion is the server computer's PLC-routable IP address, for example opc.tcp://192.168.1.50:4840, because that address identifies the same machine from the PLC's routing context before and after the download. This is the single change that resolved the network branch in the reported case.

A host name also works when the PLC runtime resolves names through DNS or a host entry, but the name adds a second thing that can break. Use the IP address unless name resolution on the controller is verified, and pin the address with a static configuration or a reservation so a renewed lease does not silently move the server.

Why does a corrected endpoint still fail with BadCommunicationError? #

A reachable endpoint with a still-failing session points at security-policy negotiation: the client may only choose from the policies the server advertises, and if the two lists share no policy, the session dies with the same BadCommunicationError and no certificate change can fix it. In the reported case the server offered only Basic128Rsa15 and Basic256, and the CODESYS runtime supported neither, so the intersection was empty.

There are exactly two ways out. Configure the server to also advertise a policy the runtime supports, or move the controller to a runtime and firmware combination that supports one of the server's advertised policies. Decide this before touching certificates, because certificate work on an empty intersection changes nothing.

Which security policy can the PLC runtime actually use? #

Policy support is a property of the device family, its firmware and the runtime version; in the reported CODESYS 3.5 SP19 Patch 7 case, supported targets expose Basic256Sha256 in the device's Security Settings, while the failing runtime supported neither of the server's two policies. On a supported target, open the device's communication settings, then Security Settings, then the CmpOPCUAServer folder, change the Communication Policy to Basic256Sha256, and restart the PLC.

The version boundaries reported in that case: the matching firmware was identified for the PFC100 and PFC200 families together with CODESYS V3.5 SP21 PATCH 1; the PFC300 was tied to CODESYS 3.5.21.10 or higher in a later release; and the EC300 (752-8303/8000-0002) had no such firmware at the time of the report. Read the compatibility statement for your own device before planning the upgrade.

Two cautions. First, the settings some replies quote in /etc/codesys3.d/CODESYSControl_User.cfg, section [CmpOPCUAServer], entries such as SECURITY.CommunicationMode=ALL and SECURITY.CommunicationPolicy=POLICY_BASIC128RSA15, configure the CODESYS server role; they do not give the outbound data source a policy it lacks. Second, Basic128Rsa15 is deprecated as unsafe, and setting SECURITY.AllowUserPasswordOnPlaintext=YES to let passwords cross an unencrypted channel weakens credential protection — it is not a remedy for a policy mismatch, and on a machine that runs it should stay disabled.

After policy negotiation works, finish trust: generate the server certificate in the CODESYS Security Screen, attempt the connection, then move the client certificate from quarantine to the trusted area — the same quarantine-to-trusted step described for trusting an OPC UA client certificate on the controller, applied on whichever side holds the store you are fixing.

What is the fix procedure that verifies the connection end to end? #

Fix the endpoint first, then the policy, then the certificates, in that order, because each step removes one branch of the failure and the remaining error message tells you which branch you are still on.

  1. Record the full endpoint URL stored in the data source configuration, host, port and policy.
  2. Replace localhost with the server computer's PLC-routable IP address.
  3. Verify the path: link LEDs, subnet arithmetic from the worked example above, and TCP reachability of the endpoint port from the PLC's segment.
  4. List the policies the server advertises and the policies the runtime supports; if the lists do not intersect, enable Basic256Sha256 on the server and set the runtime's Communication Policy to match, or upgrade to a firmware and runtime pair that supports one of the server's policies.
  5. Restart the runtime after a policy change, generate or confirm the server certificate, make one connection attempt, and move the client certificate from quarantine to trusted.

Decision for each case. If the endpoint held localhost, change it to the server's IP address — that alone fixed the network branch in the reported case. If the policy lists do not intersect, close the gap on the server side or upgrade the controller, because certificates cannot. If the transport opens but the session still fails, the remaining fault is certificate trust or user authentication, checked on the side the error names. If the endpoint is corrected, one policy is shared, certificates are trusted, and the call still fails, the fault is the physical or routed path: link, subnet, gateway or firewall on the exact port.

Questions asked

Does a successful browse from the engineering PC prove the deployed connection will work?

No. The browse runs on the PC, so it proves only that the PC can reach the endpoint. Once downloaded, the data source calls from the PLC over the PLC's own cable, subnet, gateway and firewall path, which the browse never exercised. Treat the browse as a configuration check, not a path test.

What port should the endpoint URL use?

Use the port the server's endpoint is configured to listen on. Port 4840 is the widely used OPC UA default, but servers are routinely placed on other ports, and the PLC must be able to open TCP to that exact port. Read the port from the server's endpoint configuration rather than assuming the default.

Do trusted certificates survive an application download?

On a CODESYS runtime the certificate stores belong to the device, not to the downloaded application, so a program download does not clear the trusted list. Reinstalling the runtime image or replacing the controller does, so plan to re-trust the client and server certificates after either of those.

Why does my server advertise only Basic128Rsa15 and Basic256?

Those are legacy policy sets that older server stacks enable by default. Enable a modern policy such as Basic256Sha256 in the server's own security configuration and restart it, and a runtime that supports that policy can negotiate the session. If the server stack offers nothing your runtime supports, the runtime or firmware has to change instead.

Keep reading

  • Explainer

    Where an OPC UA server sits when Python reads PLC data

    No IEC 61131 function block transports data by itself: OPC UA (IEC 62541) needs a server that maps PLC variables into an address space, and a classic S7-300 has none, so the endpoint comes from a server or gateway on a computer beside the CPU. Point Python at that server's opc.tcp endpoint, keep actuator control and the comm-loss fallback in the PLC, and accept Python's results as requested setpoints.

    SCADA and data logging

  • 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

  • How-to

    Connecting a CODESYS HMI on Windows to an S7-1500 PLC

    Yes, it works. Use OPC UA with the S7-1500 as server and the CODESYS HMI as client when the PC only supervises; use a CODESYS Control Win runtime with target visualization over a PROFINET controller/device link when the PC must also run logic. The PROFINET path adds one single-device license on top of the runtime; the OPC UA path adds none.

    SCADA and data logging