fpompermaier / onvif

Java ONVIF library
Apache License 2.0
193 stars 88 forks source link

Please, provide the examples #1

Closed maxglu closed 6 years ago

maxglu commented 7 years ago

Hello! You have done a great job, but it need of some examples for modern devices, like Axis cameras or other. I tried use Main class from onfif-java package, but application crush with error

javax.xml.ws.soap.SOAPFaultException: MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood

othnin commented 7 years ago

Hi, I'm pretty new to J2EE and wanted to look into a using/contributing to a project like you have. Do you have any basic examples on how to get it going.

fpompermaier commented 7 years ago

Yes!are you interested in the onvif or telegram part?

othnin commented 7 years ago

In the ONVIF part. I have a camera and wanted to look at building a web framework around it to learn J2EE

fpompermaier commented 7 years ago

If you want to use an Ovif device try to have a look at https://github.com/fpompermaier/onvif/blob/master/udoo-bot/src/main/java/org/udoo/telegram/bot/TelegramMsgHandler.java.

You need to write something like:

try {
    System.out.println("Connect to camera, please wait ...");
    OnvifDevice cam = new OnvifDevice(deviceIp, user, password);
    System.out.printf("Connected to device %s (%s)\n", cam.getDeviceInfo(), deviceName);
} catch (ConnectException | SOAPException e1) {
    System.err.println("No connection to device with ip " + deviceIp + ", please try again.");
    System.exit(0);
}

Then you can take a picture from the camera with:

MediaUri sceenshotUri = cam.getMedia().getSnapshotUri(profileToken);
File tempFile = File.createTempFile("tmp", ".jpg");
FileUtils.copyURLToFile(new URL(sceenshotUri.getUri()), tempFile);

If you want to contribute in any way I'll be great! Just let me know in case

@maxglu Sorry I didn't see your issue before today... :octocat: Could you give me more details about the error you've got? Which version of Onvif specification is your device using?

DrDobry commented 7 years ago

Hello, Thank you for providing these examples. Can you please provide an example how to make Event subscription (PullPoint Subscription) in java, similar to the the option in Onvif device manager, so I can for example take snapshot once motion is detected.

fpompermaier commented 7 years ago

I didn't have time to work on that part, I've just created the client stubs to connect to the Event WS but I didn't found any good documentation about how to use those services...if you have time to look into it and issue a PR with an example I'll be happy to test it and merge it.

fpompermaier commented 7 years ago

HI @DrDobry, did you have any time to look ad the event subscription part? That would be definitely interesting

DrDobry commented 7 years ago

@fpompermaier Sorry, I'm very new to java and onvif, just started working and i needed to make event listening on camera, among other things. I made ad-hoc solution by making a camera send notification message once motion is detected (in camera UI), and i read that message on tcp port, best I could do. I might go back to that if need be, but boss seams happy enough with current solution.

othnin commented 7 years ago

I took a look at the code you have in the de/onvif/Main.java it connects but I get a "Warning: Mismatch between Java model and WSDL model found, For wsdl operation {http://www.onvif.org/ver10/events/wsdl http://www.onvif.org/ver10/events/wsdl} CreatePullPointSubscription, There is no matching wsdl fault with detail QName {http://www.onvif.org/ver10/events/wsdl}ResourceUnknwonFault http://www.onvif.org/ver10/events/wsdl}ResourceUnknwonFault."

The code blows up when I try to any of the operations such as url, profiles. when I try to get the cam.getMedia.getProfiles() Gets a Client received SOAP faukt from server:Server not Authorized.

I am using an Amcrest camera. I'm not familiar with the ONVIF yet. Do I need a specific wsdl file?

On Tue, Mar 7, 2017 at 2:42 PM, Flavio Pompermaier <notifications@github.com

wrote:

If you want to use an Ovif device try to have a look at https://github.com/fpompermaier/onvif/blob/master/udoo-bot/src/main/java/ org/udoo/telegram/bot/TelegramMsgHandler.java.

You need to write something like:

try { System.out.println("Connect to camera, please wait ..."); OnvifDevice cam = new OnvifDevice(deviceIp, user, password); System.out.printf("Connected to device %s (%s)\n", cam.getDeviceInfo(), deviceName); onvifCameras.put(deviceName, cam); onvifCamerasTokens.put(deviceName, profileToken); } catch (ConnectException | SOAPException e1) { System.err.println("No connection to device with ip " + deviceIp + ", please try again."); System.exit(0); }

Then you can take a picture from the camera with:

MediaUri sceenshotUri = cam.getMedia().getSnapshotUri(profileToken);File tempFile = File.createTempFile("tmp", ".jpg");FileUtils.copyURLToFile(new URL(sceenshotUri.getUri()), tempFile);

If you want to contribute in any way I'll be great! Just let me know in case

@maxglu https://github.com/maxglu Sorry I didn't see your issue before today... [image: :octocat:] Could you give me more details about the error you've got? Which version of Onvif specification is your device using?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fpompermaier/onvif/issues/1#issuecomment-284852236, or mute the thread https://github.com/notifications/unsubscribe-auth/ABaXAfHDdKJaLvbvAGJa6QM_K6TIxa7wks5rjcEYgaJpZM4L2veT .

fpompermaier commented 7 years ago

I've tried to debug the Event thing but I didn't manage to solve it. If you look at MiscTest class I've added more code to reach the creation of the subsciption. Unfortunately I didn't find a way to create a PullPointSubcription to get PullMessages from it. It should also be easier for you to set cam ip, username and password parameters (the errors you have I think are mostly caused by a bad configuration ).

Things should work like described in http://ssbu-t.psn-web.net/For_developer/ONVIF/Panasonic_OnvifV241_ApplicationNote.pdf but probably there still something missing :( It seems like the event wsdl (that declares 2 portTypes) is not translated properly into Java classes because I expect to find a PullPointSubcription class but there's no such class within the client stubs

fpompermaier commented 7 years ago

I understood that we need to be able to use WS-Notification system. A good example is depicted at https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_A-MQ/6.1/html-single/WS-Notification_Guide/#WSNTutorial-Pullpoint. Probably the code must be changed in some point to support it..

fpompermaier commented 7 years ago

I pushed some code modification in order to support WS-Notification. In MiscTest there's the code that interface with it. Unofortunately I'm still trying to understand how to correctly subscribe to the PullPoint..

jfeferman commented 7 years ago

I am very interested in trying out this project to control a remote camera. Could you please provide a basic configuration path for setting up in Eclipse? Thank you.

fpompermaier commented 7 years ago

What do you mean exactly for configuration path? If you want to use this library you just need to install the library using mvn install (from command line or from Eclipse, as you prefer) and then you can use it as a dependency in your project adding the following dependency in the pom.xml:

<dependency>
   <groupId>org.onvif</groupId>
  <artifactId>onvif-java</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>
jfeferman commented 7 years ago

Thanks for the handholding. I got it to work. Perhaps OnvifDevice could use a port, although I did add it to the end of my deviceIp and accessed the camera.

Stakhmich commented 7 years ago

how i can subscribe to camera with BaseNotification?

fpompermaier commented 7 years ago

The part related to notification is still to develop...I've tried to set up a working example in https://github.com/fpompermaier/onvif/blob/master/onvif-java/src/main/java/de/onvif/MiscTests.java but I didn't have time to work on it. I think it shouldn't be that hard to make it work if someone is familiar with WS-Notification

Stakhmich commented 7 years ago

i am new in WS-Notification. Could you share some links? Or describe basic steps?

fpompermaier commented 7 years ago

I'm also new to WS-Notification unfortunately..however in https://github.com/fpompermaier/onvif/blob/master/onvif-java/src/main/java/de/onvif/MiscTests.java there's the code to start play with it. If you ever be able to make it work issue a PR ;)

ghost commented 6 years ago

[ERROR] Failed to execute goal on project udoo-app: Could not resolve dependencies for project org.springframework.boot:udoo-app:war:1.3.5.RELEASE: The following artifacts could not be resolved: jdk.dio:device-io:jar:1.1, org.onvif:onvif-java:jar:1.0-SNAPSHOT: Could not find artifact jdk.dio:device-io:jar:1.1 in ifun (http://localhost:8081/nexus/content/groups/public/) -> [Help 1]

Hi, Where can I find this jdk.dio.device-io.jar? I search maven center reposity and can't find it. Thanks.

fpompermaier commented 6 years ago

I'll look into that ASAP..however you could ignore udoo-app module..I should remove it and move it into another git repo.. For the moment you could disable its compilation commenting the module tag within the main pom.xml

ghost commented 6 years ago

Ok. Thank you for your hard work.

fpompermaier commented 6 years ago

Hi to all, I've just removed the unrelated project from this repository and now everything should be very simple to set up and test (I moved all test classes to test folder). For the moment I close this issue. Feel free to open new issues to improve this lib or contribute (in particular to interface with event and alarms)

quonn77 commented 6 years ago

Hi Flavio, I have just forked your code and made some minor changes about wsdl stub generation, multi network adapter support, WSSE Usernametoken support. I am now investigating on how Events subscription works.....If you have some news about it please let me know ;-).

fpompermaier commented 6 years ago

Great news! Feel free to issue a PR whenever you want to