IpCamera: New IP Camera Binding

@toroid
I’ll take a look to see if I can work around that when a camera replies with null instead of a valid location. I can probably get it going but you will need to move all 3 controls to then get an accurate location from the camera so a rule on openhab startup to specify a XYZ location would be a good idea.

@frutak
The illegal characters are in the header of the reply back from the camera. You could confirm this with the Linux tool ‘tcpdump’. The : in the request is not there, it is my way of showing where the url starts and stops in the logs so I can see if carriage returns and the like are entered in by users in the snapshot override field. The best way forward would be to use tcpdump to confirm if it is the camera or not so if it is a bug in the netty library we can report it. I think it will be the camera so check for a newer firmware.

@TomBeerten
Your camera is not giving a content length on how large the picture is and this is causing the issue. I may be able to work around this camera issue by guessing how much ram is needed but I would need to err on the larger side and it would place more ram requirements on your server. Maybe 500kb per picture I could guess at. At the least I will detect and put something in the logs that this is happening so thanks for the log.

@frutak
Does your password contain one of the illegal characters? Your camera uses the password in the url string and this goes into the headers so that may be the cause. A space may not be allowed, so try a password that is less complex with no spaces and see if it solves the issue.

thanks for your answer

PTZ works well in onvif device manager.

i can add the cam and it;s online but it do not work


2018-05-31 03:15:38.291 [ome.event.ItemCommandEvent] - Item 'ONVIFGenericIPCameraWithONVIFSupport_Pan' received command 48

==> /var/log/openhab2/openhab.log <==

2018-05-31 03:15:38.300 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.ipcamera.handler.IpCameraHandler@10f8329': null
java.lang.NullPointerException: null
	at org.openhab.binding.ipcamera.handler.IpCameraHandler.setAbsolutePan(IpCameraHandler.java:927) [80:org.openhab.binding.ipcamera:2.3.0.201805252336]

	at org.openhab.binding.ipcamera.handler.IpCameraHandler.handleCommand(IpCameraHandler.java:878) [80:org.openhab.binding.ipcamera:2.3.0.201805252336]

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [106:org.eclipse.smarthome.core:0.10.0.oh230]

	at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [106:org.eclipse.smarthome.core:0.10.0.oh230]

	at com.sun.proxy.$Proxy180.handleCommand(Unknown Source) [80:org.openhab.binding.ipcamera:2.3.0.201805252336]

	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:75) [113:org.eclipse.smarthome.core.thing:0.10.0.oh230]

	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [113:org.eclipse.smarthome.core.thing:0.10.0.oh230]

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [106:org.eclipse.smarthome.core:0.10.0.oh230]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [106:org.eclipse.smarthome.core:0.10.0.oh230]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]


	at java.lang.Thread.run(Thread.java:748) [?:?]


could you kindly advise?

Matt,

Do you need anything from me for this? camera type e.g.?
Is there anything i have to do to solve the problem, camera setting e.g.?

Many Thanks.

New build 31-05-2018 has these changes:

  • Now supports images from cameras that dont specify a content-length header. @TomBeerten and @Yura_Qenf can you test this build please as both of you are the only ones to report this issue. Note: cameras that do this need to keep their snapshots below 512kbytes in size or an error will get thrown.

  • PTZ fix for cameras that reply with null when asked what their current position is. @nakh_Home and @toroid can you test as you both reported this.

  • Instar major bug fix.

  • Dahua possibly now has motion alarm features. Big THANKS to @psyciknz for the help with this.

Tried with both HIK and Onvif Generic
I got the error again:

Do u have all three controls linked? Pan tilt and zoom are they all linked and able to be moved in paper ui? Also did you test absolute movement in onvif device manager as there are three types of movement with onvif.

Yes, I have all three elements tied.


At Pan tilt shows in the console an error that I cited above.
When I do zoom I have the following shows:

PTZ works fine in onvif device manager

Ok, now no errors, the image is displayed! :slight_smile:

Still getting this in log with 31-5 build

2018-05-31 22:40:08.788 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - About to connect to the IP Camera using the ONVIF PORT at IP:192.168.192.85:80
2018-05-31 22:40:24.425 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Fetching the number of Media Profile this camera supports.
2018-05-31 22:40:35.827 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Checking the selected Media Profile is a valid number.
2018-05-31 22:40:35.832 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Fetching a Token for the selected Media Profile.
2018-05-31 22:40:35.834 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Auto fetching the snapshot URL for the selected Media Profile.
2018-05-31 22:40:44.964 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - About to interrogate the camera to see if it supports PTZ.
2018-05-31 22:40:58.513 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Camera is reporting that it does NOT support Absolute PTZ controls via ONVIF
2018-05-31 22:40:58.517 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Finished with PTZ, now fetching the Video URL's the camera supports.
2018-05-31 22:41:20.231 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:20.261 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:25.212 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:25.237 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:30.199 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:30.219 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:40.195 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-05-31 22:41:40.203 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.

i will be glad to test but i am blocked

New build 01-06-2018 has these changes:

  • Fixed bug that was only in last build that would update the image channel twice.
  • Added more logging and some changes to PTZ to help narrow down where problems lie. Need debug output from logs if you have trouble.
  • Increased time to wait for slow cameras or slow networks from 4 seconds to 10.

@tnemrap
Try this latest build, also please make sure you have the " Enable Hikvision-CGI" box ticked which is found on the same page as enabling ONVIF. I now own 3 HIKVISION cameras which are working for me after ticking that box. Also these cameras are far slower to respond to requests for a snapshot and if your network is busy with traffic it may have caused issues

Still some errors in log it is on GB Lan but it is constantly recording to Surveillance Station so it can be a performance issue with the camera.

2018-06-01 20:51:40.205 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 20:51:40.206 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 20:51:53.515 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 20:51:53.515 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 20:55:15.706 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 20:55:15.706 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 21:03:15.385 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.
2018-06-01 21:03:15.385 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Camera at 192.168.192.85:80 is not closing the connection quick enough.

New build 03-06-2018 has following changes:

  • Backend code now operates for the first time with full Async (can do multiple requests at the same time). Let me know if older releases work when this one does not, as well as your camera brand and some debug log output.
  • HIKVISION has a heap of changes to make the alarms detect faster and more reliable. @ArsalanAlli you were wanting faster detection, give it a try.
  • Some camera brands now allow NVR channel to be selected, needs more work done as people give feedback.
  • Improved online/offline detection when multiple cameras are setup.
  • Some cameras now default to having a snapshot url entered by default so they connect faster.

@tnemrap Now I have had a chance to do some testing with my new hik cameras I have found the resolution and compression settings determine how fast you can get a picture from the camera. Mine at 4k needs at least 3 seconds to transfer the snapshot and that is on a fast network with no other traffic.

Thanks,

i have tried and the camera but it do not work

2018-06-03 21:36:01.250 [ERROR] [ing.ipcamera.handler.IpCameraHandler] - Can not connect to the camera at 192.168.1.40:80 check your network for issues.

2018-06-03 21:36:05.935 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.ipcamera.handler.IpCameraHandler@1aa61c': null

	at org.openhab.binding.ipcamera.handler.IpCameraHandler.setAbsolutePan(IpCameraHandler.java:1033) [80:org.openhab.binding.ipcamera:2.3.0.201806011247]

	at org.openhab.binding.ipcamera.handler.IpCameraHandler.handleCommand(IpCameraHandler.java:981) [80:org.openhab.binding.ipcamera:2.3.0.201806011247]

2018-06-03 21:36:07.082 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.ipcamera.handler.IpCameraHandler@1aa61c': null

	at org.openhab.binding.ipcamera.handler.IpCameraHandler.setAbsolutePan(IpCameraHandler.java:1033) [80:org.openhab.binding.ipcamera:2.3.0.201806011247]

	at org.openhab.binding.ipcamera.handler.IpCameraHandler.handleCommand(IpCameraHandler.java:981) [80:org.openhab.binding.ipcamera:2.3.0.201806011247]

2018-06-03 21:36:11.254 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - About to connect to the IP Camera using the ONVIF PORT at IP:192.168.1.40:80

2018-06-03 21:36:17.768 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Fetching the number of Media Profile this camera supports.

2018-06-03 21:36:22.025 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Checking the selected Media Profile is a valid number.

2018-06-03 21:36:22.028 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Fetching a Token for the selected Media Profile.

2018-06-03 21:36:22.030 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - About to interrogate the camera to see if it supports PTZ.

2018-06-03 21:36:52.583 [ERROR] [ing.ipcamera.handler.IpCameraHandler] - NPE occured when trying to connect to the camera with ONVIF

2018-06-03 21:44:55.003 [ERROR] [ing.ipcamera.handler.IpCameraHandler] - Can not connect to the camera at 192.168.1.40:80 check your network for issues.

the ptz works well in ONVIF device manager.

@nakh_Home
Change the log to DEBUG:

1.Start Karaf console
2.Enter in

log:set DEBUG org.openhab.binding.ipcamera 

Need debug output.

Thanks

After enabling the debug log


2018-06-04 10:57:08.518 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Getting configuration to initialize a new IP Camera at IP 192.168.1.40
2018-06-04 10:57:08.523 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - About to connect to the IP Camera using the ONVIF PORT at IP:192.168.1.40:80
2018-06-04 10:57:16.560 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Fetching the number of Media Profile this camera supports.
2018-06-04 10:57:19.559 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Checking the selected Media Profile is a valid number.
2018-06-04 10:57:19.561 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Fetching a Token for the selected Media Profile.
2018-06-04 10:57:19.564 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - Auto fetching the snapshot URL for the selected Media Profile.
2018-06-04 10:57:22.487 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - About to fetch some information about the Media Profiles from the camera
2018-06-04 10:57:22.490 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - ********************* Media Profile 0 details reported by camera at IP:192.168.1.40 *********************
2018-06-04 10:57:22.492 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Camera will use this Media Profile unless you change it in the binding by pressing on the pencil icon in PaperUI.
2018-06-04 10:57:22.494 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 0 is named:VideoEncoder_1
2018-06-04 10:57:22.496 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 0 uses video encoder	:H_264
2018-06-04 10:57:22.498 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 0 uses video quality	:10.0
2018-06-04 10:57:22.500 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 0 uses video resoltion	:1280 x 720
2018-06-04 10:57:22.502 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 0 uses video bitrate	:0
2018-06-04 10:57:22.505 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - ********************* Media Profile 1 details reported by camera at IP:192.168.1.40 *********************
2018-06-04 10:57:22.507 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 1 is named:VideoEncoder_2
2018-06-04 10:57:22.509 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 1 uses video encoder	:H_264
2018-06-04 10:57:22.512 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 1 uses video quality	:10.0
2018-06-04 10:57:22.514 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 1 uses video resoltion	:640 x 320
2018-06-04 10:57:22.517 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Media Profile 1 uses video bitrate	:0
2018-06-04 10:57:22.519 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - About to interrogate the camera to see if it supports PTZ.
2018-06-04 10:57:33.201 [ERROR] [ing.ipcamera.handler.IpCameraHandler] - NPE occured when trying to connect to the camera with ONVIF
2018-06-04 10:57:33.532 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Connecting to camera at IP:192.168.1.40 with request GET:/onvif/snapshot
2018-06-04 10:57:33.912 [DEBUG] [ipcamera.internal.MyNettyAuthHandler] - ++++++++ Auth Handler created ++++++++ /onvif/snapshot
2018-06-04 10:57:33.926 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - ++++++++ Handler 1 created ++++++++ :/onvif/snapshot
2018-06-04 10:57:34.039 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - New request has been sent to camera.
2018-06-04 10:57:34.063 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Connection to camera is closed. GET:/onvif/snapshot
2018-06-04 10:57:34.068 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - ------- Closing Handler, leaving 0 handlers alive ------- :/onvif/snapshot

getting a loop of “New request has been sent to camera.”

what should be the http port or https port ?

Thanks for your help

Hi Matt,

updated the binding but still have the same issue. My debug log:


PaperUI:

And Habpanel:
image

Thx again

@TomBeerten
Your camera appears to not send any jpeg data before the “lasthttpcontent” which triggers the binding to close the connection. Can you check the link shown in the Image URL works if you manually enter it into a browser?

@nakh_Home
Next build will have more logging in the area needed to narrow the PTZ issue down and should handle the issue smoother.
I suspect you have a second issue as this line seems strange…

Media Profile 0 uses video bitrate	:0  

It should be higher than 0.
Try the link in any brower to check it works. You need to find a link that works in a browser if this one does not.

http://192.168.1.40/onvif/snapshot

http://192.168.1.40/onvif/snapshot

image

i am trying to add this camera Y203S