pythonjavaopc-uaopcua-client

OCP UA status=Bad_ConnectionClosed using digital petri


My work has an existing python script for connecting to an OPC UA Server. I'm all very basic and I'm trying to make a better system in java. However, I keep getting an exception with the message status=Bad_ConnectionClosed anytime i try and do anything with the server. The existing python script involved with establishing a connection and retrieving a value goes as follows:

from opcua import Client, ua

opcClient = Client("opc.tcp://localhost:54321")

opcClient.connect;

valueNode = opcClient.get_node("ns=1;s=measure.value")

I'm not kidding that is all that is done here. The best open source library I could find for java was Digital Petri through maven, com.digitalpetri.opcua:ua-client:1.0.4 (also tried 1.1.1)

My attempt to connect goes as follows:

OpcUaClient opcUaClient = new OpcUaClient(OpcUaClientConfig.builder().setEndpointUrl("opc.tcp://localhost:54321").build()).connect().get();

This line throws the exception mentioned, and I cannot then retrieve a node or anything else:

Apon further research i found a client example on digital petris github page, https://github.com/kevinherron/ua-client-sdk/blob/master/ua-client-tests/src/test/java/com/digitalpetri/opcua/sdk/client/OpcUaClientIT.java

After pulling the required config values using the Python script, I was able to replicate the part relevant to connecting the client to a server:

 EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints("opc.tcp://localhost:54321").get();

        EndpointDescription endpoint = Arrays.stream(endpoints)
                .filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getSecurityPolicyUri()))
                .findFirst().orElseThrow(() -> new Exception("no desired endpoints returned"));

        OpcUaClientConfig clientConfig = OpcUaClientConfig.builder()
                .setApplicationName(LocalizedText.english("Pure Python Client"))
                .setApplicationUri("urn:freeopcua:client")
                .setEndpoint(endpoint)
                .setRequestTimeout(uint(60000))
                .build();

        OpcUaClient client = new OpcUaClient(clientConfig);

However, once again at the very first line EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints("opc.tcp://localhost:54321").get(); i get the same exception.:

I have tried adding /discovery at the end of the URL (as reccommended).

There is no certificate system in place and an anonymous login is expected.


Solution

  • but either way digital petri seems to be the go to for java and should work fine.

    The digitalpetri OPC UA repos are archived and explicitly point you towards Eclipse Milo as the replacement.