I've just checked out the Eclipse Milo Project (https://projects.eclipse.org/proposals/milo), which seems to be a great project for an "open" OPC UA Client/Server even with the implemented OPC Stack. The project on github (https://github.com/eclipse/milo) contains a Hello World example, where an OPC Server is started and an example node is sent and received from the client. Everything works fine!
But in my next step, I wanted to check if the server is configured correctly. Therefore I've installed Matrikon Explorer, but the Explorer is stating out "No OPC servers installed on this machine" right after start (while the hello world example with a running OPC Server is running of course).
Also checked, if SAP Plant Connectivity is recognizing the OPC Server (which is the goal of my project) -> "Found no OPC Server on your system/localhost"
Where is my problem, what do I have to do, to install and configure the Server correctly?
Here's the Hello World Example:
public static void main(String[] args) throws Exception {
// Start server
int port = 12686;
String serverName = "test-server";
OpcUaServerConfig serverConfig = OpcUaServerConfig.builder()
.setBindPort(port)
.setCertificateManager(new DefaultCertificateManager())
.setCertificateValidator(new DefaultCertificateValidator(createTempDir()))
.setServerName(serverName)
.setUserTokenPolicies(singletonList(USER_TOKEN_POLICY_ANONYMOUS))
.build();
OpcUaServer server = new OpcUaServer(serverConfig);
server.getNamespaceManager().registerAndAdd(
"urn:eclipse:milo:opcua:test-namespace",
idx -> new HelloNamespace());
server.startup();
while(true){
System.out.println("server running");
}
}
Matrikon Explorer is an OPC-COM/DA client, and is probably interrogating the OPC Enum service in order to find registered COM clients.
OPC-UA is an entirely different, platform independent, technology. The concept of registration still exists, but it's not forced by default.
Try using an OPC-UA client like UaExpert to connect. Given the configuration you've copied, you'll want to point UaExpert at the endpoint URL opc.tcp://localhost:12686/test-server
I'm guessing there will be an issue once you connect with the partially implemented "hello world" namespace. I'll make sure we get a fully usable namespace example committed this week.
You can also look at the OpcUaClientIT integration test class for various client functionality and another example of setting up a server.
Related
I am trying to connect to an OPC server of a Siemens S7 1200 PLC. For this I used the Matrikon application
That is configured on my local machine. With the JeasyOPC library I can make the connection, so it is like this:
JOpc jopc = new JOpc("localhost","Matrikon.OPC.SiemensPLC.1","JOPC1");
JOpc.coInitialize();
But this library can only be used in Windows and has problems when compiling binaries in 64.
So I have tried with OPC Foundation UA JAVA Legacy and I would like to make the same connection, however in the examples we ask for many more things:
String publicHostname = InetAddress.getLocalHost().getHostName();
String url = "opc.tcp://localhost:102/"; // ServerExample1
// String url = "Matrikon.OPC.SiemensPLC.1"; // This not work for me
EndpointDescription[] endpoints = myClient.discoverEndpoints(url);
I would like to emulate the operation of jeasyOPC as far as possible, in any case I can not find any example that works for me.
I would appreciate any example that would help me have a base client that would work with the Matrikon server
Thank you.
Okay. I answer to myself.
After many searches I have found my error:
There are two types of OPC: DA and UA.
The first of all (the DA) is to which I could connect with:
JOpc jopc = new JOpc ("localhost", "Matrikon.OPC.SiemensPLC.1", "JOPC1");
This version of the protocol is the one used historicaménte windows, uses COM libraries and can only be implemented under a Windows computer.
The second, the OPC UA, is the new implementation and connects like this:
String url = "opc.tcp: // localhost: 102 /"; // ServerExample1
This version is already compatible with Windows, Linux and any system that is capable of running the libria.
The problem was that, in my case, the S7 1200 only uses OPC DA, which made the UA option unfeasible for me if it did not use a compatible gateway.
I hope this information will help someone who is in my situation.
Greetings.
I am trying to connect opc kepware server through a Java program, I want to know what jar files can be used to connect to KepwareserverEx.V5 and what is the code without the use of password and username.
I have referenced http://www.opcconnect.com/uakit.php, and https://github.com/digitalpetri/ua-server-sdk, but it doesn't have anything that doesn't connect without a username and a pawssword. I have a program in vb that connects to kepware using Interop.OPCAutomation.dll file and uses the code:
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect("Kepware.KEPServerEX.V5", "")
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add("MPM Group")
ConnectedGroup.UpdateRate = 1000
ConnectedGroup.IsSubscribed = True
ConnectedGroup.IsActive = True
I want to write Java code in a similar way. Searched through the internet to see various examples, but none have the above connection without a username and password not being specified.
First of all, I assume that you have created an "anonymous" and "SecurityPolicy.None" endpoint on KepServerEX.
You refer to digitalpetri's old and server SDK. The new project is called "Milo". I can recommend you take a look at the Milo project's client SDK examples using this link. There is an application of anonymous identity and none security policy.
In terms of jar, you can either build your client-sdk (see example here) or directly download the client-sdk jar from Maven Central.
NB Milo is considered to be in incubation. That is to say, it is not mature yet. Be careful using it in production systems.
Yes that's right. The security policy is none on the KepwareServerEX. I made some permission changes on the server where Kepware exists, so that my localhost computer would be able to talk to the Kepware server host. Provided credentials for my localhost, and able to connect.
I've created a basic java EE 7 chat application - with Intellij Ultimate 14 - that lets users send messages and receive messages (using sessions, no room, no user identification).
I've tried the application by itself on a glassfish 4.1 server on windows 8.1 : it works perfectly.
Now I'm trying to run it in an ubuntu 14.04 server hosted in virtualbox (same glassfish and java ee version), this is so that I can later work on clustering the application.
When I install the application on the ubuntu server, using the web based interface (that I access from the windows host), I can load the application in a chrome, but the websocket doesn't seem to connect properly and therefore I cannot send any message at all.
By the way, I've tried connecting the websocket on the glassfish installed on the windows and it works fine.
Here is the html side of the app connecting the websocket to the server :
var host = "ws://" + document.location.host + "/GlassFish7_war/test";
wsocket = new WebSocket(host);
wsocket.onmessage = onMessage; // the function that displays received messages
and here is the relevant part of the server accepting the socket :
#ServerEndpoint("/test")
public class MyEndPoint {
#OnOpen
public void openConnection(Session session) {
session.getBasicRemote().sendText("hello there !");
// [...]
}
}
you guessed it : I never receive the "hello there !" message on the client side.
I think the problem might come from the configuration of the virtualbox network, yet I can't seem to figure out what to do about it. Currently I have a bridged and a NAT adapter.
Any help would be greatly appreciated !
Thanks a lot !
I have 2 grizzly applications I'd like to run side by side on different URLs on the same server. When I change my url from localhost to api.url.local for local debugging it throws a java.nio.channels.UnresolvedAddressException. Is there something I need to do in order for java to recognize another URL (ie - modify hosts file)? Or am I going in the wrong direction?
I'm currently on Windows but will be deploying to Linux. (If it were up to me, I'd run Linux)
public class Main {
public static final URI BASE_URI = getBaseURI();
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(9998).build();
}
protected static HttpServer startServer() throws IOException {
ResourceConfig rc = new PackagesResourceConfig("com.my.package.api.resources");
rc.getFeatures()
.put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
}
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext annotationCtx = new AnnotationConfigApplicationContext(Config.class);
HttpServer httpServer = startServer();
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nHit enter to stop it...", BASE_URI, BASE_URI));
System.in.read();
httpServer.stop();
}
}
Running two different applications under different urls on the same machine with one ip address is quite easy. But can require some setup depending on what you want to do.
My assumption is that you're doing this on your development machine. The biggest issue here is that the two servers require different port numbers.
Server #1
http://localhost:8080/
Server #2
http://localhost:8081/
If you want named instances instead. You will have to update your hosts file to point the named instance you want to your local machine. BUT, you'll still have to do separate ports per application.
Server #1
http://api.url.local:8080/
Server #2
http://api.url.local2:8081/
You will also have to update your tomcat (I'm assuming you're using tocmat) config. In the element, I believe you will have to update the 'name' attribute to be the name of your application's URL.
Friendly warning, if you are using the same IP Address, but different host names, SSL certificates will not work very well. Typically in that sort of setup you will need either a wildcard or unified communications certificate.
When you deploy to production, I would recommend using Apache HTTP Server as a proxy to your two applications and have two separate IP Address' unless you can use a SSL wildcard or a unified communications certificate.
This part of the answer is for if you wanted to run one application under two different URLs.
Proxy your application with a Apache Http Server instance and use mod_proxy to forward your two different server names or ip address' to the same Java instance.
My recommendation though, just run two instances of your application. Don't worry too much about resources, hardware is really cheep and worth a lot less then worrying about how to run one instance for two different sites.
I have a locally working JAVA RMI Applicaton(Server & Client).
I have used Eclipse & a plugin(Genady) to write & run these applications.
There are three parts in my project:
1. Server
2. Interface(Common for both client & server)
3. Client
Local deployment, using Eclipse(+plugin), works perfectly. The client uses the common interface(added to the "Build Path") to communicate(to n fro) with the server(which also has the common interface added to its Build Path in eclipse).
And now, I'm planning to test the same system in two different computers, both having Internet connection.
What do I do now?
Should I be installing Apache on one computer(Server) & put the Server+Interface files(class-files) into the web-accessible directory? & then run the Client-files(having both client & interface class files) from another computer(Client)??
Can someone help me configure this? I mean, a step-by-step guide as to what I should be doing in order for the remote deployment to work?
Is using Apache(or any web server application) compulsory?? Any other alternative for my application to work without using a web server(I mean, like direct connection or something?)?
(I feel I've given all the info that is required. But if any more info is needed, please ask.)
This is my final year project & my final demo is coming up soon!
Thank you, in advance!
I don't know what Genady does since I rarely use Eclipse.
Developing RMI applications is very easy anyway.
Pack the server code and run it on the remote machine (the R in RMI)(a.k.a. server host), it should register itself with the Registry which by default uses port 1099 but you can create a registry in any port you like:
MyRemoteInterface stub = (MyRemoteInterface) UnicastRemoteObject.exportObject(server, 0); //I don't know if this is needed anymore, or you could make the "server" extend UnicastRemoteObject
int thePortUsedInTheServer = 1099; //default
Registry registry = Registry.createRegistry(thePortUsedInTheServer);
registry.rebind("Server", stub));
Pack the client code and run it on the client(s) (the M+I in RMI), it should locate the Registry in the remote machine (host+port):
String host = ...; //the host where the server is
int port = ...; //the port used in the server
Registry registry = LocateRegistry.getRegistry(host, port);
MyRemoteInterface stub = (MyRemoteInterface)registry.lookup("Server");
stub.myRemoteMethod(); //call your remote methods
The javadoc should help you out. Nothing else is required, no Apache, etc. Watch out for aggresive anti-virus software, firewalls, and the like. Those are the only real issues after you get the gist of it.