IpCamera: New IP Camera Binding

No to both answers. After openhab reboot i get, after half an hour:

2019-05-10 15:49:46.807 [ERROR] [me.core.internal.events.EventHandler] - Creation of ESH-Event failed, because one of the registered event factories has thrown an exception: Error invoking #valueOf(String) on class ‘org.eclipse.smarthome.core.library.types.RawType’ with value 'data:image/jpeg;base64,

java.lang.IllegalStateException: Error invoking #valueOf(String) on class ‘org.eclipse.smarthome.core.library.types.RawType’ with value 'data:image/jpeg;base64,

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseSimpleClassName(ItemEventFactory.java:190) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseType(ItemEventFactory.java:158) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.getState(ItemEventFactory.java:136) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.createStateChangedEvent(ItemEventFactory.java:131) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.createEventByType(ItemEventFactory.java:84) ~[?:?]

at org.eclipse.smarthome.core.events.AbstractEventFactory.createEvent(AbstractEventFactory.java:51) ~[?:?]

at org.eclipse.smarthome.core.internal.events.EventHandler.createESHEvent(EventHandler.java:121) ~[?:?]

at org.eclipse.smarthome.core.internal.events.EventHandler.handleEvent(EventHandler.java:95) ~[?:?]

at org.eclipse.smarthome.core.internal.events.EventHandler.handleEvent(EventHandler.java:72) ~[?:?]

at org.eclipse.smarthome.core.internal.events.ThreadedEventHandler.lambda$0(ThreadedEventHandler.java:67) ~[?:?]

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

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source) ~[?:?]

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

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

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseSimpleClassName(ItemEventFactory.java:181) ~[?:?]

... 10 more

Caused by: java.lang.IllegalArgumentException: Illegal base64 character 5

at java.util.Base64$Decoder.decode0(Base64.java:714) ~[?:?]

at java.util.Base64$Decoder.decode(Base64.java:526) ~[?:?]

at java.util.Base64$Decoder.decode(Base64.java:549) ~[?:?]

at org.eclipse.smarthome.core.library.types.RawType.valueOf(RawType.java:74) ~[?:?]

at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source) ~[?:?]

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

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

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseSimpleClassName(ItemEventFactory.java:181) ~[?:?]

I will post more when it happens again (heap space)

See this post on how to increase heap space.

Tnx, was 360mb, i extended to 512mb.

Lets see…

@matt1 i still get some random errors like this:

019-05-11 16:33:38.970 [ERROR] [me.core.internal.events.EventHandler] - Creation of ESH-Event failed, because one of the registered event factories has thrown an exception: Error invoking #valueOf(String) on class ‘org.eclipse.smarthome.core.library.types.RawType’ with value 'data:image/jpeg;base64,/9j

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseSimpleClassName(ItemEventFactory.java:190) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseType(ItemEventFactory.java:158) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.getState(ItemEventFactory.java:136) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.createStateChangedEvent(ItemEventFactory.java:131) ~[?:?]

at org.eclipse.smarthome.core.items.events.ItemEventFactory.createEventByType(ItemEventFactory.java:84) ~[?:?]

at org.eclipse.smarthome.core.events.AbstractEventFactory.createEvent(AbstractEventFactory.java:51) ~[?:?]

at org.eclipse.smarthome.core.internal.events.EventHandler.createESHEvent(EventHandler.java:121) ~[?:?]

at org.eclipse.smarthome.core.internal.events.EventHandler.handleEvent(EventHandler.java:95) ~[?:?]

at org.eclipse.smarthome.core.internal.events.EventHandler.handleEvent(EventHandler.java:72) ~[?:?]

at org.eclipse.smarthome.core.internal.events.ThreadedEventHandler.lambda$0(ThreadedEventHandler.java:67) ~[?:?]

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

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source) ~[?:?]

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

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

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseSimpleClassName(ItemEventFactory.java:181) ~[?:?]

... 10 more

Caused by: java.lang.IllegalArgumentException: Illegal base64 character 29

at java.util.Base64$Decoder.decode0(Base64.java:714) ~[?:?]

at java.util.Base64$Decoder.decode(Base64.java:526) ~[?:?]

at java.util.Base64$Decoder.decode(Base64.java:549) ~[?:?]

at org.eclipse.smarthome.core.library.types.RawType.valueOf(RawType.java:74) ~[?:?]

at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source) ~[?:?]

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

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

at org.eclipse.smarthome.core.items.events.ItemEventFactory.parseSimpleClassName(ItemEventFactory.java:181) ~[?:?]

... 10 more

I also outputs the raw image content i think, i removed this for reading purposes.

How often does it occur? Do things keep working after it happens? This is not something I have ever seen and I am guessing it is the snapshots are the cause which the code has not changed in ages and has been flawless for me. Perhaps there is a size limit for images, have you tried changing the resolution and compression/quality settings to see if it stops with a different setting? Is it only a particular brand of camera doing it? Any help narrowing it down would be great.

It happens once in a while, as far as i can see a couple of times a day. If it would be possible to just skip the image binary dump part from this exception that would be a solution for me; currently the log’s grow huge because of these dumps

Thanks for reporting it.

Have you tried cleaning the tmp and cache folders and rebooting? There has to be a reason why I have never seen this before nor had it reported by anyone else. It may be a camera doing something non standard… Try disabling some cameras to narrow down the cause as it may be a bottleneck of some kind, the root of a problem should always be looked at and not worked around. You can filter the error from the logs by using the method described in the readme file. It is not something I can change in the binding as the binding is not the code that is creating the error and it is indicating an earlier fault/warning/error has occurred.

As it is happening once or twice a day now i don’t thinks it’s related to cache or tmp folders. I have rebooted a couple of times the past days. I copied the complete error in a separate file for you to download so you see what is actually dumped: dump

Hello, first of all, thanks for your work on this binding.

Any chance to get Dahua IVS (Tripwire / CrossLine) alarm support added to the binding?

Here is a link to latest Dahua HTTP API I was able to find: http://pasty.sk/ohab/dahua_http_api_for_ipc_v1.56.pdf

Thanks!

It should already be working, does it not work for you? If not put the logs into TRACE (how to do this is in the readme) and supply what the camera is sending the binding when the alarm is triggered. Since I am trying to keep/reuse channels so the naming is consistent it is probably called line crossing not tripwire. Take a look at the available channels in PaperUI and you will see a lot of features that have been added for Dahua cameras.

I have seen weird things happen if you don’t clean the cache and tmp folders out with Openhab and it is one of the top 2 things that annoys me about Openhab. Whenever you change something this should be the first thing you try.

Ok and howto clean the cache?

In Linux the following should work, for other platforms search this forum…

sudo service openhab2 stop && sudo rm -rf /var/lib/openhab2/cache/* && sudo rm -rf /var/lib/openhab2/tmp/* && sudo reboot

Hi @matt1,

thank you very much for the great binding you created!
It took me while to get it going, since it also requires to get the matching settings going on the camera side. But nevertheless, I am learning a lot and it is fun.
Here are a few questions:

  • Is there any way to get the current pan/tilt/zoom information from the camera?
  • My camera can be programmed with several PTZ positions; How can I select those using your binding?

Cheers…

Ok cache cleared and rebooted. Let’s see what it brings…

@sl92656
Glad you like the binding and find it useful. If you have any feedback on what you found a hurdle to get it going please do so as I use it to update the readme and the binding and feedback from new comers is valuable as often when you program the binding you overlook how someone else thinks or expects something to work…

Great to hear as most people here don’t mind giving people help if they put the effort in to learn instead of wanting to be spoon fed.

Yes it is implemented but sadly not all cameras are truly ONVIF as there is no requirement to have a camera independently tested before it can advertise onvif compliance, often they passed a onvif 1.1 test and hence they put a label on the product when we are now at > 2.4 onvif version.
My Amcrest camera will report its position, but note that the binding only does this when the camera is connected for the first time, if you move the camera in a 3rd party app and want Openhab to reflect the change then this would need to be a feature request.

There is an example of how I do it in the readme file for my baby monitor. I use openhab to create the presets as this will be cleaner and more consistent between camera brands and also it allows you to learn the concept of SCENES which can be used for lighting in your home. It also means you don’t need to setup things in the camera and your backups contain a better snapshot of how your setup truly is. Do some searches in the solution forum for scenes and you will find posts like this one that will explain how to tackle things in new ways you may not have thought about…

@matt1,

thanks for the quick response!

Consider this a feature request. Here is my reasoning:
I use the camera’s motion detection feature to create an alarm. To setup the motion detection zone, I do have to use the camera app (i.e. in my case “Amcrest Web View” on an iMAC for my Amcrest IP4M-1051) to define the zone. In order to match the Pan/Tilt/Zoom values in Openhab, I move the sliders to somehow match the position, which is a trial/error activity. It would therefore greatly be simplified if the binding would provide channels that show the currently active position, at which point I can copy those values over to OpenHAB. If those values are not updated on a regular basis, the process gets quite tedious.

I forgot you can already do that with the REFRESH command, you will need to poll the camera which is why it is not the default behaviour…

example…

items:

Dimmer CamPan "Pan [%d] left/right" { channel="ipcamera:DAHUA:001:pan" }
Dimmer CamTilt "Tilt [%d] up/down" { channel="ipcamera:DAHUA:001:tilt" }
Dimmer CamZoom "Zoom [%d] in/out" { channel="ipcamera:DAHUA:001:zoom" }

rule:

rule "refresh"
when
    Time cron "0 */2 * * * ? *"
then
    //your ITEMS to refresh every 2 minutes here
    CamPan.sendCommand(RefreshType.REFRESH)
    CamTilt.sendCommand(RefreshType.REFRESH)
    CamZoom.sendCommand(RefreshType.REFRESH)
end

Hi Matt

Have you had a chance to implement this yet?

No, while it is a <5 minute job to add the feature, the recent changes made to the build system mean I can not create any more builds until the binding is converted to the new bundle format and finding 4+ hours to sit down and do that is a challenge. Next rainy day…

Hi @matt1,

thanks for the pointer. One thing to mention, in order for the REFRESH command to work I had to add

import org.eclipse.smarthome.core.types.RefreshType

to the top of the rule file.

I then got the info from your binding, BUT, it seems that the values reported did not come from the camera. Here is my log; after several movements of the camera (from outside of openHAB):

2019-05-16 21:39:10.020 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Pan is updating to:78 and the cam value is 0.55999994
2019-05-16 21:39:10.079 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Tilt is updating to:80 and the cam value is 0.5999999
2019-05-16 21:39:10.098 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Zoom is updating to:1 and the cam value is 0.007812
2019-05-16 21:39:15.015 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Pan is updating to:78 and the cam value is 0.55999994
2019-05-16 21:39:15.036 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Tilt is updating to:80 and the cam value is 0.5999999
2019-05-16 21:39:15.045 [DEBUG] [g.openhab.binding.ipcamera.handler.IpCameraHandler] - Zoom is updating to:1 and the cam value is 0.007812

None of the values changed. Is the binding requesting the PTZ position from the camera when the REFRESH command is sent or is the binding just reporting back the item value without polling the camera?