Search code examples
javaopc-uamilo

How can I get OPC UA node name in Eclipse Milo?


I followed ManagedSubscriptionDataExample.java (https://github.com/eclipse/milo/blob/master/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/ManagedSubscriptionDataExample.java) example on github page to read OPC nodes from PLC S7-1200.

Value for nodes are getting updated but I can't get name.

For code:

subscription.addDataChangeListener((items, values) -> {
                for (int i = 0; i < items.size(); i++) {
                    logger.info(
                            "subscription value received: item={}, value={}, valueID={}",
                            items.get(i).getNodeId(), values.get(i).getValue(), items.get(i).getReadValueId());
                }

I get response:

INFO: subscription value received: item=NodeId{ns=4, id=4}, value=Variant{value=false}, valueID=ReadValueId(nodeId=NodeId{ns=4, id=4}, attributeId=13, indexRange=null, dataEncoding=QualifiedName{name=null, namespaceIndex=0})

I see that name is null and that there is no method to get name for node. But if I use OPC client "OPC Expert" I can also get names for nodes as they are on PLC: enter image description here

Is there any other option to get name of the variable?


Solution

  • UaExpert is doing more bookkeeping than you are doing. You should have knowledge of which Nodes you have created MonitoredItems for and be able to get the BrowseName or DisplayName attribute from those Nodes.

    Inside that callback you have access to the NodeId - that should be your key to get to the Node and any attributes you are interested in.