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

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

Back to the top