Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [milo-dev] How to confirm Milo server registration with LDS server

Hi Kevin,

Please help me to solve this issue.  
Please advise me in fixing the problem.


Thanks,
Dhanasekar

On Wed, Mar 4, 2020 at 5:08 PM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
Hi Kevin,

I have changed code like this,

public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {



String ServerURI ="urn:eclipse:milo:examples:client";
String ProductURI = "https://opcfoundation.org/";
LocalizedText[] myServerName = new LocalizedText[]{LocalizedText.english("eclipse milo opc-ua client")};
ApplicationType ServerType = ApplicationType.Server;
String myGateWayURI = NULL;
String[] myDiscoveryURLs = new String[]{ "opc.tcp://quanta:4840"};
String mySemaphorePath = NULL;
Boolean IsOnline = Boolean.TRUE;

MdnsDiscoveryConfiguration[] myDiscoveryConfig = new MdnsDiscoveryConfiguration[]{null,null} ;

UaStackClient stackClient = client.getStackClient();

logger.info("Dhanasekar @ReadExample.java ={}", client.connect().get());
// synchronous connect
client.connect().get();

RequestHeader requestHeader = stackClient.newRequestHeader(
NodeId.NULL_VALUE,
stackClient.getConfig().getRequestTimeout()
);
RegisteredServer myServer = new RegisteredServer(ServerURI,ProductURI,myServerName,ServerType,NULL,myDiscoveryURLs,NULL,IsOnline);

RegisterServerRequest myServerRequest = new RegisterServerRequest (requestHeader,myServer);

client.connect().get(); //Added by dhanasekar

RegisterServerResponse rsr = (RegisterServerResponse)stackClient.sendRequest(myServerRequest).get();

logger.info("Dhanasekar @ReadExample.java rsr.getResponseHeader().getServiceResult() ={}", rsr);

// synchronous read request via VariableNode
VariableNode node = client.getAddressSpace().createVariableNode(Identifiers.Server_ServerStatus_StartTime);
DataValue value = node.readValue().get();

logger.info("StartTime={}", value.getValue().getValue());

// asynchronous read request
readServerStateAndTime(client).thenAccept(values -> {
DataValue v0 = values.get(0);
DataValue v1 = values.get(1);

logger.info("State={}", ServerState.from((Integer) v0.getValue().getValue()));
logger.info("CurrentTime={}", v1.getValue().getValue());

future.complete(client);
});
}

When I run ReadExample.java, I am getting below error,


16:10:10,390 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:10:10,391 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:10:10,392 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/dhanasekar.j/Documents/BMS/OPC/milo-master/milo-examples/client-examples/target/classes/logback.xml]
16:10:10,393 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
16:10:10,393 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/C:/Users/dhanasekar.j/Documents/BMS/OPC/milo-master/milo-examples/server-examples/target/classes/logback.xml]
16:10:10,393 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/C:/Users/dhanasekar.j/Documents/BMS/OPC/milo-master/milo-examples/client-examples/target/classes/logback.xml]
16:10:10,671 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
16:10:10,764 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
16:10:10,767 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
16:10:10,855 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
16:10:10,855 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
16:10:10,855 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
16:10:10,856 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
16:10:10,856 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
16:10:10,857 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:10:10,858 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4b1c1ea0 - Registering current configuration as safe fallback point

16:10:11.737 [main] INFO  o.e.m.examples.server.ExampleServer - security temp dir: C:\Users\DHANAS~1.J\AppData\Local\Temp\security
16:10:11.764 [main] INFO  o.e.m.examples.server.KeyStoreLoader - Loading KeyStore at C:\Users\DHANAS~1.J\AppData\Local\Temp\security\example-server.pfx
16:10:12.262 [main] INFO  o.e.m.examples.server.ExampleServer - pki dir: C:\Users\DHANAS~1.J\AppData\Local\Temp\security\pki
16:10:14.087 [main] INFO  o.e.m.opcua.sdk.server.OpcUaServer - Eclipse Milo OPC UA Stack version: 0.3.5-SNAPSHOT
16:10:14.087 [main] INFO  o.e.m.opcua.sdk.server.OpcUaServer - Eclipse Milo OPC UA Server SDK version: 0.3.5-SNAPSHOT
16:10:14.143 [main] INFO  o.e.m.examples.server.ExampleServer - dhanasekar -> Calling before OpcUaServer(serverConfig) :
16:10:14.631 [main] INFO  o.e.m.opcua.sdk.server.OpcUaServer - dhanasekar -> Inside OpcUaServer.java constructor :
16:10:20.149 [main] INFO  o.e.m.o.stack.server.UaStackServer - dhanasekar -> Inside  UaStackServer.java constructor :
16:10:23.137 [main] INFO  o.e.m.o.s.s.n.OpcUaNamespace - dhanasekar  inside ManagedAddressSpace.java
16:10:24.394 [main] INFO  o.e.m.o.s.s.n.OpcUaNamespace - Loaded nodes in 1257ms.
16:10:24.610 [main] INFO  o.e.m.o.s.s.n.ServerNamespace - dhanasekar  inside ManagedAddressSpace.java
16:10:24.710 [main] INFO  o.e.m.e.server.ExampleNamespace - dhanasekar  inside ManagedAddressSpace.java
16:10:24.710 [main] INFO  o.e.m.e.server.ExampleNamespace - dhanasekar  ExampleNamespace.java folderNodeId: NodeId{ns=2, id=HelloWorld1}
16:10:24.711 [main] INFO  o.e.m.e.server.ExampleNamespace - dhanasekar  ExampleNamespace.java folderNodeId: NodeId{ns=2, id=DJ-TEST}
16:10:24.711 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld1}
16:10:24.711 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.711 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.711 [main] INFO  o.e.m.e.server.ExampleNamespace - dhanasekar  ExampleNamespace.java folderNode: org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode@62e6b5c8
16:10:24.711 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/ArrayTypes}
16:10:24.711 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.711 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.759 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/ScalarTypes}
16:10:24.759 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.759 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.760 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/OnlyAdminCanRead}
16:10:24.761 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.761 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.773 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/OnlyAdminCanWrite}
16:10:24.773 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.773 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.774 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/Dynamic}
16:10:24.774 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.774 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.799 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/DataAccess}
16:10:24.799 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.799 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:24.888 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java getNodeId(): NodeId{ns=2, id=HelloWorld/WriteOnly}
16:10:24.888 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.HasTypeDefinition: NodeId{ns=0, id=40}
16:10:24.888 [main] INFO  o.e.m.o.s.server.nodes.UaFolderNode - dhanasekar  UaFolderNode.java Identifiers.FolderType.expanded(): ExpandedNodeId{ns=0, id=61, serverIndex=0}
16:10:25.096 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://BLRB1DT166:12686/milo to 0.0.0.0:12686 [None/None]
16:10:25.489 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://BLRB1DT166:12686/milo to 0.0.0.0:12686 [Basic256Sha256/SignAndEncrypt]
16:10:25.489 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://BLRB1DT166:12686/milo/discovery to 0.0.0.0:12686 [None/None]
16:10:25.489 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://10.1.61.38:12686/milo to 0.0.0.0:12686 [None/None]
16:10:25.489 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://10.1.61.38:12686/milo to 0.0.0.0:12686 [Basic256Sha256/SignAndEncrypt]
16:10:25.489 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://10.1.61.38:12686/milo/discovery to 0.0.0.0:12686 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://BLRB1DT166.VTPPL.COM:12686/milo to 0.0.0.0:12686 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://BLRB1DT166.VTPPL.COM:12686/milo to 0.0.0.0:12686 [Basic256Sha256/SignAndEncrypt]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://BLRB1DT166.VTPPL.COM:12686/milo/discovery to 0.0.0.0:12686 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://127.0.0.1:12686/milo to 0.0.0.0:12686 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://127.0.0.1:12686/milo to 0.0.0.0:12686 [Basic256Sha256/SignAndEncrypt]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint opc.tcp://127.0.0.1:12686/milo/discovery to 0.0.0.0:12686 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://BLRB1DT166:8443/milo to 0.0.0.0:8443 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://BLRB1DT166:8443/milo to 0.0.0.0:8443 [Basic256Sha256/Sign]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://BLRB1DT166:8443/milo/discovery to 0.0.0.0:8443 [None/None]
16:10:25.490 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://10.1.61.38:8443/milo to 0.0.0.0:8443 [None/None]
16:10:25.491 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://10.1.61.38:8443/milo to 0.0.0.0:8443 [Basic256Sha256/Sign]
16:10:25.491 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://10.1.61.38:8443/milo/discovery to 0.0.0.0:8443 [None/None]
16:10:25.491 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://BLRB1DT166.VTPPL.COM:8443/milo to 0.0.0.0:8443 [None/None]
16:10:25.491 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://BLRB1DT166.VTPPL.COM:8443/milo to 0.0.0.0:8443 [Basic256Sha256/Sign]
16:10:25.491 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://BLRB1DT166.VTPPL.COM:8443/milo/discovery to 0.0.0.0:8443 [None/None]
16:10:25.491 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://127.0.0.1:8443/milo to 0.0.0.0:8443 [None/None]
16:10:25.492 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://127.0.0.1:8443/milo to 0.0.0.0:8443 [Basic256Sha256/Sign]
16:10:25.492 [main] INFO  o.e.m.o.stack.server.UaStackServer - Binding endpoint https://127.0.0.1:8443/milo/discovery to 0.0.0.0:8443 [None/None]
16:10:25.844 [main] INFO  o.e.m.e.client.ClientExampleRunner - security temp dir: C:\Users\DHANAS~1.J\AppData\Local\Temp\security
16:10:25.861 [main] INFO  o.e.m.examples.client.KeyStoreLoader - Loading KeyStore at C:\Users\DHANAS~1.J\AppData\Local\Temp\security\example-client.pfx
16:10:31.653 [main] INFO  o.e.m.e.client.ClientExampleRunner - Using endpoint: opc.tcp://quanta:4840 [None/None]
16:10:32.560 [main] INFO  o.e.m.opcua.sdk.client.OpcUaClient - Eclipse Milo OPC UA Stack version: 0.3.5-SNAPSHOT
16:10:32.560 [main] INFO  o.e.m.opcua.sdk.client.OpcUaClient - Eclipse Milo OPC UA Client SDK version: 0.3.5-SNAPSHOT
16:10:38.932 [NonceUtilSecureRandom] INFO  o.e.m.o.stack.core.util.NonceUtil - SecureRandom seeded in 0ms.
16:10:38.994 [main] INFO  o.e.milo.examples.client.ReadExample - Dhanasekar @ReadExample.java =org.eclipse.milo.opcua.sdk.client.OpcUaClient@7e0b9178
16:10:39.057 [main] ERROR o.e.m.e.client.ClientExampleRunner - Error running client example: UaServiceFaultException: status=Bad_SessionIdInvalid, message=The session id is not valid.
java.util.concurrent.ExecutionException: UaServiceFaultException: status=Bad_SessionIdInvalid, message=The session id is not valid.
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at org.eclipse.milo.examples.client.ReadExample.run(ReadExample.java:96)
at org.eclipse.milo.examples.client.ClientExampleRunner.run(ClientExampleRunner.java:146)
at org.eclipse.milo.examples.client.ReadExample.main(ReadExample.java:48)
Caused by: org.eclipse.milo.opcua.stack.core.UaServiceFaultException: status=Bad_SessionIdInvalid, description=The session id is not valid.
at org.eclipse.milo.opcua.stack.client.UaStackClient.lambda$deliverResponse$5(UaStackClient.java:273)
at org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$Task.run(ExecutionQueue.java:119)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
16:10:39.058 [ForkJoinPool.commonPool-worker-3] ERROR o.e.m.e.client.ClientExampleRunner - Error running example: UaServiceFaultException: status=Bad_SessionIdInvalid, message=The session id is not valid.
java.util.concurrent.ExecutionException: UaServiceFaultException: status=Bad_SessionIdInvalid, message=The session id is not valid.
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at org.eclipse.milo.examples.client.ReadExample.run(ReadExample.java:96)
at org.eclipse.milo.examples.client.ClientExampleRunner.run(ClientExampleRunner.java:146)
at org.eclipse.milo.examples.client.ReadExample.main(ReadExample.java:48)
Caused by: org.eclipse.milo.opcua.stack.core.UaServiceFaultException: status=Bad_SessionIdInvalid, description=The session id is not valid.
at org.eclipse.milo.opcua.stack.client.UaStackClient.lambda$deliverResponse$5(UaStackClient.java:273)
at org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$Task.run(ExecutionQueue.java:119)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)


Process finished with exit code 0


On Tue, Mar 3, 2020 at 9:09 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:
Try simplifying it and replacing all the CompletableFuture stuff you've added with something like this:

RegisterServerResponse rsr = (RegisterServerResponse) stackClient.sendRequest(myServerRequest).get();

On Tue, Mar 3, 2020 at 7:30 AM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
Hi Kevin,

I am working on to register Milo server with open62541 LDS server. 
I have added code in ReadExample.java to register. 
How to confirm Milo server successfully registered with open62541 LDS ?.
I mean from log. Because I am not seeing any message in Eclipse IDE when I run ReadExample.java. 

I have copied some code from RegistrationHelper.java
Please correct me if I am going in the wrong direction.
I have never worked in registration of LDS service. 

I have commented out  futureRegisterResult.complete(response.getResponseHeader().getServiceResult()); in below code. Because, I am getting error.

ReadExample.java

/*
* Copyright (c) 2019 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.examples.client;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import com.google.common.collect.ImmutableList;
import org.bouncycastle.cert.ocsp.Req;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.nodes.VariableNode;
import org.eclipse.milo.opcua.stack.client.UaStackClient;
import org.eclipse.milo.opcua.stack.core.Identifiers;
import org.eclipse.milo.opcua.stack.core.serialization.UaResponseMessage;
import org.eclipse.milo.opcua.stack.core.types.builtin.*;
import org.eclipse.milo.opcua.stack.core.types.enumerated.ApplicationType;
import org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.eclipse.milo.opcua.stack.core.types.structured.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//dhanasekar - addded start
import org.eclipse.milo.opcua.stack.core.types.structured.RegisterServerRequest;
import org.eclipse.milo.opcua.stack.core.types.structured.RegisterServerResponse;
import org.eclipse.milo.opcua.stack.core.types.structured.RegisteredServer;
//dhanasekar - added end

import static ch.qos.logback.core.joran.action.ActionConst.NULL;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;



public class ReadExample implements ClientExample {

public static void main(String[] args) throws Exception {

ReadExample example = new ReadExample();

new ClientExampleRunner(example, true).run();
}

private final Logger logger = LoggerFactory.getLogger(getClass());




@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {

//UaStackClient myClient = new UaStackClient();

String ServerURI ="urn:eclipse:milo:examples:client";
String ProductURI = "https://opcfoundation.org/";
LocalizedText[] myServerName = new LocalizedText[]{LocalizedText.english("eclipse milo opc-ua client")};
ApplicationType ServerType = ApplicationType.Server;
String myGateWayURI = NULL;
String[] myDiscoveryURLs = new String[]{ "opc.tcp://10.1.61.38:12686/milo/discovery"};
String mySemaphorePath = NULL;
Boolean IsOnline = Boolean.TRUE;

MdnsDiscoveryConfiguration[] myDiscoveryConfig = new MdnsDiscoveryConfiguration[]{null,null} ;

CompletableFuture<StatusCode> futureRegisterResult = new CompletableFuture<>();

//ExtensionObject[] discoveryConfig = new ExtensionObject[] {ExtensionObject.BodyType("Eclipse_Milo_OPCUA_Winodws","NA")};


UaStackClient stackClient = client.getStackClient();

logger.info("Dhanasekar @ReadExample.java ={}", client.connect().get());
// synchronous connect
client.connect().get();

RequestHeader requestHeader = stackClient.newRequestHeader(
NodeId.NULL_VALUE,
stackClient.getConfig().getRequestTimeout()
);
RegisteredServer myServer = new RegisteredServer(ServerURI,ProductURI,myServerName,ServerType,NULL,myDiscoveryURLs,NULL,IsOnline);

RegisterServerRequest myServerRequest = new RegisterServerRequest (requestHeader,myServer);

//ExtensionObject[] mdnsDiscoveryConfig = new MdnsDiscoveryConfiguration(myServerName, new String[0]);

client.connect().get(); //Added by dhanasekar

CompletableFuture<UaResponseMessage> myfuture = stackClient.sendRequest(myServerRequest);

future.whenComplete((response, ex) -> {
if (response == null) {
futureRegisterResult.completeExceptionally(ex);
} else {
//futureRegisterResult.complete(response.getResponseHeader().getServiceResult());
}
});

//RegisterServer2Request myServer2Request = new RegisterServer2Request(requestHeader,myServer,discoveryConfig);

// synchronous connect
//client.connect().get();

// synchronous read request via VariableNode
VariableNode node = client.getAddressSpace().createVariableNode(Identifiers.Server_ServerStatus_StartTime);
DataValue value = node.readValue().get();

logger.info("StartTime={}", value.getValue().getValue());

// asynchronous read request
readServerStateAndTime(client).thenAccept(values -> {
DataValue v0 = values.get(0);
DataValue v1 = values.get(1);

logger.info("State={}", ServerState.from((Integer) v0.getValue().getValue()));
logger.info("CurrentTime={}", v1.getValue().getValue());

future.complete(client);
});
}

private CompletableFuture<List<DataValue>> readServerStateAndTime(OpcUaClient client) {
List<NodeId> nodeIds = ImmutableList.of(
Identifiers.Server_ServerStatus_State,
Identifiers.Server_ServerStatus_CurrentTime);

return client.readValues(0.0, TimestampsToReturn.Both, nodeIds);
}

}
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev

Back to the top