IpCamera: New IP Camera Binding

The latest version of the binding does not update the IMAGE channel like older bindings, it only updates every 5th snapshot. Use the new snapshots.mjpeg feature instead as I may be removing the image channel from the binding to encourage people to do things a better way.

Did you solve the camera reporting it had user/pass issues? Does the above explain it?

@Desmond206x
I found the reason and the next build should work.

@halloween
Depends on how often your version of every now and then is. I see this happen probably once a week with 4 cameras working away every second, have not looked into why it occurs as it is too hard to capture. It is marked as a WARN because it is not critical and should not cause issues but in general warnings can be an indicator of an issue if it happens every 5 minutes to pluck a time out of the air.

1 Like

Thanks for this great binding :+1:
I recently bought a DAHUA HFW1320S-W (cheap with basic features) and can report it is working with the binding:

  • motion events
  • mjpg streaming
  • snapshots
  • controlling the ir led

However I am seeing some warnings in my log:

openhab.log
2020-01-15 13:51:25.238 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !!!! Camera has closed a channel 	URL: Cause reported is: {}
io.netty.util.concurrent.BlockingOperationException: DefaultChannelPromise@225977d(incomplete)
	at io.netty.util.concurrent.DefaultPromise.checkDeadLock(DefaultPromise.java:461) ~[bundleFile:4.1.42.Final]
	at io.netty.channel.DefaultChannelPromise.checkDeadLock(DefaultChannelPromise.java:159) ~[bundleFile:4.1.42.Final]
	at io.netty.util.concurrent.DefaultPromise.awaitUninterruptibly(DefaultPromise.java:267) ~[bundleFile:4.1.42.Final]
	at io.netty.channel.DefaultChannelPromise.awaitUninterruptibly(DefaultChannelPromise.java:137) ~[bundleFile:4.1.42.Final]
	at io.netty.channel.DefaultChannelPromise.awaitUninterruptibly(DefaultChannelPromise.java:30) ~[bundleFile:4.1.42.Final]
	at org.openhab.binding.ipcamera.handler.IpCameraHandler.sendHttpRequest(IpCameraHandler.java:541) ~[?:?]
	at org.openhab.binding.ipcamera.internal.MyNettyAuthHandler.processAuth(MyNettyAuthHandler.java:177) ~[?:?]
	at org.openhab.binding.ipcamera.internal.MyNettyAuthHandler.channelRead(MyNettyAuthHandler.java:227) ~[?:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) [bundleFile:4.1.42.Final]
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) [bundleFile:4.1.42.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:328) [bundleFile:4.1.42.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:302) [bundleFile:4.1.42.Final]
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) [bundleFile:4.1.42.Final]
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) [bundleFile:4.1.42.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) [bundleFile:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) [bundleFile:4.1.42.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) [bundleFile:4.1.42.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) [bundleFile:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) [bundleFile:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) [bundleFile:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) [bundleFile:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) [bundleFile:4.1.42.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) [bundleFile:4.1.42.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [bundleFile:4.1.42.Final]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [bundleFile:4.1.42.Final]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]
2020-01-15 13:51:27.308 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !?! Channel that was found idle could not be located in our tracking. !?!
2020-01-15 13:51:27.310 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Can't find ch when removing handler 		URL:
2020-01-15 13:51:28.482 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !?! Channel that was found idle could not be located in our tracking. !?!
2020-01-15 13:51:28.483 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Can't find ch when removing handler 		URL:
2020-01-15 13:51:29.946 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - There are 13 channels being tracked, cleaning out old channels now to try and reduce this to 12 or below.
2020-01-15 13:51:29.947 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Cleaning the channels has just found a connection with wrong open state.
2020-01-15 13:51:29.948 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Cleaning the channels has just found a connection with wrong open state.
2020-01-15 13:51:29.948 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Cleaning the channels has just found a connection with wrong open state.
2020-01-15 13:51:29.948 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - Cleaning the channels has just found a connection with wrong open state.

2020-01-15 16:10:23.203 [WARN ] [io.netty.channel.nio.NioEventLoop   ] - Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@19048e5f.
2020-01-15 16:32:01.822 [WARN ] [io.netty.channel.nio.NioEventLoop   ] - Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@5f1161a3.

where the last two warnings seem to occur only when I access the mjpg stream:

2020-01-15 16:32:01.822 [WARN ] [io.netty.channel.nio.NioEventLoop   ] - Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@5f1161a3.

Did I maybe configure something wrong or can this be safely ignored?

camera.things
Thing ipcamera:DAHUA:DAHUA1 "Kamera hinten" @ "Kameras"
[
    IPADDRESS="192.168.2.232",
    USERNAME="username",
    PASSWORD="password",
    POLL_CAMERA_MS=2000,
    SERVER_PORT=37777,
    UPDATE_IMAGE=false,
    IMAGE_UPDATE_EVENTS=1,
    ONVIF_MEDIA_PROFILE=0,
    IP_WHITELIST="DISABLE"
]

Binding version is from 20200110

That is a nice one. I changed from

to the new snapshots.mjpeg feature after upgrading: high resolution ā€œstreamā€ with two seconds update time.
Looks really great :+1:

Hey, first of all, thanks for the great binding :slight_smile:
I bought a AMCREST IP2M-841W and its working, i get the video image, notification when a motion was detected,ā€¦ exept i can not toggle the Motion Detection (activate/deactivate it when iĀ“m at home). Is it the ā€œEnable/Disable the Motion Alarmā€ toggle or am i wrong?

Try rebooting if your clear the cache openhab seems to need two reboots. Look at your logs. Update firmware on camera. Works on mine here but it is older firmware most likely so check if you can control it from a browser using the api.

Waiting for the next Version :slight_smile:

Thanks, glad it is apricated as it has been an insane amount of work to get things to the stage this could be done. Glad it works at 2 second updates as I have only tested 1 second or 1fps so far, at some point probably around 5 or 10 seconds it is going to break as the browser will assume the stream has timed out and it may be different for each browser.

I just replied about this in the post above yours to @halloween so more info thereā€¦
I did a quick look and it may be a bug in Netty, or it may be my code, or it may be an indicator of a bottleneck if it happens too often. Thanks for reporting it happens only with mjpeg streams, info like that really helps and this may explain why I donā€™t see it often as I donā€™t leave a tablet on the wall streaming 24-7.
What may be helpful is knowing if it still happens in you only use the new snapshots.mjpeg as that would narrow down what is common or different between those methods.

I use my mjpeg stream directly from the cam provided by the binding (with the adress from openhabserver:port50001ā€¦) and i saw this with the old ipcam-binding-version too.

Now i use both, the real mjpeg stream which is provided from the binding and the mjpeg-snapshot-stream and the warning is in the logs. I donĀ“t show the stream the whole time, only when i open my sub-menu on the sitemap.

Last night the warning was shown about 20 times - there i was sleeping and all my phones were shut off. About every hour i saw 1-2 lines of this warning.

Try the one just uploaded.

Sorry, while setting the camera up Iā€™ve read through many posts in this thread during the last 3 days ā€¦ except yesterday :sunglasses:

I got it working but due to the image polling being restricted I had to change my items and things. Previously I only polled for an image every 15mins and used expire 1 sec = off for the update image switch which just fetch the latest image when requested. This worked before but no longer with the new binding. To get it work with the new binding I have had to change the expire to 5sec with polling every 1 sec. I assume this is needed in order to allow enough time to capture the 5th image.

I donā€™t ever view the cameras ā€˜liveā€™ through openHAB. I have a dedicated app for thatā€¦ The nearest it gets to live viewing is when the garage door is opening and then images are updated every 10sec until the door is at an end position. About two mins, so 12 images in total. Its enough for me to check the door did actually open/close after sending the command.

I looked at your clickable thumbnail thread but I donā€™t think that is what I need,. However, I intend give it a try anyway out of curiosity.

I tried the request a snapshot feature in my browser with like below:

http://openHAB server IP:Cam server port/ipcamera.jpg.

It works but I am not sure how best to implement the feature for my use as stated above. Tips would be appreciated :slight_smile:

Your documentation took a bit of thinking at firstā€¦ what IP should be used for this featureā€¦Cam or openHAB. hhmmmm. Of course its obvious if you know a little bit of whatā€™s going on but maybe not to the novice. An example would be good here. :slight_smile:

With trace log on I still see lots of errors and the log fills up rapidly like below. Even without an image being requested.

As a matter of interest for future log posts. I replaced the nonce and IP address with xxxx. Do if I need to do that or is OK to just post the trace log as is?

020-01-16 20:47:53.290 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - EmptyLastHttpContent

2020-01-16 20:47:53.909 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Sending camera: GET: http://192.168.x.xxx/live/0/jpeg.jpg

2020-01-16 20:47:53.922 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Sending camera: GET: http://192.168.x.xxx/live/0/jpeg.jpg

2020-01-16 20:47:53.925 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpResponse(decodeResult: success, version: HTTP/1.0)

HTTP/1.0 401 Unauthorized

Server: Webs

WWW-Authenticate: Digest realm="PLC-336SPW", domain="PLC-336SPW", qop="auth", nonce="xxxxxx", opaque="xxxxxx", algorithm="MD5", stale="FALSE"

Pragma: no-cache

Cache-Control: no-cache

Content-Type: text/html

2020-01-16 20:47:53.925 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 227, cap: 227/227, unwrapped: PooledUnsafeDirectByteBuf(ridx: 533, widx: 533, cap: 1024)), decoderResult: success)

2020-01-16 20:47:53.926 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - EmptyLastHttpContent

2020-01-16 20:47:53.927 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - HTTP Result back from camera is 	:<html><head><title>Document Error: Unauthorized</title></head>

		<body><h2>Access Error: Unauthorized</h2>

		when trying to obtain <b>/live/0/jpeg.jpg</b><br><p>Access Denied

Unknown User or Wrong Password</p></body></html>

:

2020-01-16 20:47:53.985 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpResponse(decodeResult: success, version: HTTP/1.0)

HTTP/1.0 200 OK

Server: Webs

Pragma: no-cache

Cache-Control: no-cache

Content-Type: image/jpeg

2020-01-16 20:47:54.097 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 1024, cap: 1024/1024, unwrapped: PooledUnsafeDirectByteBuf(ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)

2020-01-16 20:47:54.099 [DEBUG] [ing.ipcamera.handler.IpCameraHandler] - Camera has no Content-Length header, we have to guess how much RAM.

2020-01-16 20:47:54.102 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 8192, widx: 16384, cap: 16384)), decoderResult: success)

2020-01-16 20:47:54.107 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 16384, widx: 16384, cap: 16384)), decoderResult: success)

2020-01-16 20:47:54.112 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 8192, widx: 39734, cap: 65536)), decoderResult: success)

2020-01-16 20:47:54.116 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 16384, widx: 39734, cap: 65536)), decoderResult: success)

2020-01-16 20:47:54.121 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 24576, widx: 39734, cap: 65536)), decoderResult: success)

2020-01-16 20:47:54.125 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 32768, widx: 39734, cap: 65536)), decoderResult: success)

2020-01-16 20:47:54.129 [TRACE] [ing.ipcamera.handler.IpCameraHandler] - DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 6966, cap: 6966/6966, unwrapped: PooledUnsafeDirectByteBuf(ridx: 39734, widx: 39734, cap: 65536)), decoderResult: success)

The nonce is fine you only need to be careful not to show what the binding is sending and the reply back from the camera and usually I donā€™t log what the binding sends for this reason. Digest will create lots of 401 messages this is normal and not a bug it is how it works. Basic is less secure but more efficient as you donā€™t get the extra 401.

You donā€™t need to use expire to move the control, not sure your reasoning for this. Just set the poll time to be 3minutes and leave the control turned on the whole time. The image will get updated every 15 minutes.

Yes I now need to rewrite the entire readme to discourage the use of the image channel and recommend better ways.

New build 2020-01-17 has these changes:

  • New ffmpeg based Audio Alarm, works even with RTSP only cameras.
  • Generic Onvif thing types now have access to the motion and audio alarms created by ffmpeg since cameras get auto found and added it was best to put this in for now.
  • Onvif and httponly now have extra options available to update the image on alarm events. Not tested but its re-using well tested code.
  • Onvif and httponly thing types now share their own handler so should give performance boost.
  • Ffmpeg can now generate mjpeg streams for cameras that donā€™t have any. Very experimental at the moment.

The readme will be changing a lot over the next few days as all this needs to be added.

1 Like

Do i have to delete and add my Onvif Things or sould this work without?
I think my binding jar should be from middle of decemberā€¦

If you used textual config it handles everything, but if you add with paperUI then yes you need to delete or you do not see all the new config and channels.

So long as the version you have is March 2019 or newer it should have little to no breaking changes.

Hello,
I have not clear what parameters I need to keep an ESP32 cam working.
Iā€™d read the limitation, but for my pourpose it will be not a problem have 1 FPS.

I try to add a thing ā€œHTTP only cameraā€ and I enter the following parameters

But no resoult

I try several IP variant without success, like
http://192.168.178.124/capture
on the other hand if I put the URL on the browser the ESP cam module works as normal

I had no luck to find usefull information for these case looking at older post in these topic.

Thanks a lot for helping.

Best regards,
Nicolas

1 Like

Here is what I would like to achieve:

  • Image update every 15mins. 1 image is enough.
  • Image update on manual activation of switch. 1 image is enough
  • Image update every 10sec or so while monitoring garage door movement for a duration of no longer than 2mins. 1 image every 10sec is enough. Triggered by a rule on activation of door sensor

Also,

  • Limit network traffic to the absolute minimum but maintain a good image quality.
  • I donā€™t need live streaming nor frequent image updates
  • Fast image update when when requested
  • Access via local network and outside local network. If I have to I can use a VPN but I would rather not most of the time.

Previously I achieved all of the above using a poll of 15mins plus the image update now channel with expire automatically limiting the switch ON state to 1 sec.

This doesnā€™t work for the new version of the binding.

From what I discovered so far with the new binding:
Its possible to get an immediate image update but I now need more frequent polling and a the ā€˜get image updateā€™ switch on long enough for a 5th image eg polling of 1 sec with image update on for 5sec using expire to set it to off automatically. The image update every 10sec triggered by a Rule is also possible.

Or I can get an image update every 15mins by setting the polling frequency to 180sec and every 5x180s = 15mins the image is updated as long as the ā€˜image update nowā€™ switch is set to ON. ie permanently

It seems I canā€™t do both of the above unless I use two things for the same camera. Is that possible?

Am I missing something here, another approach for example ?

If stress on the openHAB cloud server needs to be reduced then couldnā€™t this also be achieved by limiting the amount of images updated in given interval rather than limiting it to every 5th image as it is. Say max continuous image update interval of 1sec with min polling frequency 1sec. ie one image per ON/OFF toggle of the image update switch. Then it would as before and also there would be no need for me to use the expire 1s OFF as I do it.

I am sorry if I am talking rubbishā€¦ I am just trying to adapt what I had before and working very well to the new binding. I think what I had was using very little bandwidth but gave me the images I needed to check on things. As I said I donā€™t use openHAB for live streaming but only as quick check all is well. If I see in the images something that is is of concern then I use another dedicated app and VPN for live streaming.

editā€¦

I got it working as I want with:

Poll_Camera_MS 200 in the camera Thing plus for the update image item switch
with expire=ā€œ1s,command=OFFā€

For the 15min regular update interval I used a rule triggered by a 15m expire timer switch.

So, the net effect of the new binding poll camera for me is I changed from 15mins to 200ms polling! Its still only a 1 image update in 1 sec due to the 5th image restriction.

Thank you for the feedback and info. What I donā€™t understand is the following.

  1. What is wrong with fetching a snapshot more often? Do you have to pay for data?
  2. Why every 15 minutes? Is that displayed on a tablet non stop? What is the reason if this is an internal network?

The data is not transferred to your viewing device unless you have it open. It could be updating every 10 seconds but until you open and look nothing is sent to your phone. So it is only supplied on demand. I would just set it to every 10 seconds and have it update that often the whole time.

I could make it so that the image channel is only limited when the poll time is below 5 seconds. This would make it easier to get your once every 15 minute goal. Also makes it less confusing. Then if you open a separate image item with ten second refresh and using ipcamera.jpg as the source it would work as desired. This would need zero rules to work, only that you open a link to view the ten second image item when you wish to get more updates.

Hi,
With my Dahua IPC-HDBW4431R-AS when rebooting camera, I doesnā€™t have anymore alarm triggering.

2020-01-14 04:01:56.361 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !!!! Camera has closed the channel 	URL:/cgi-bin/eventManager.cgi?action=attach&codes=[All] Cause reported is: {}
2020-01-14 04:01:56.463 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - The alarm stream was not running for camera 192.168.2.200, re-starting it now