IpCamera: New IP Camera Binding

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

Hi Matt,

I am viewing from sitemap from phone and laptop. Inside and outside my local network, at work, at home, WiFi or mobile connection. I don’t bother about the data usage as its small. The camera images are located on the top level of my site map and sometimes I leave it open. Mostly I don’t specifically check the images but as I use the app for other things I pass over them and take a glancing view.

The 15mins interval is just so I get a quick check all is OK as I use the openHAB app for other things without specifically checking cams all the time. eg if Someone parked on my drive, Blinds failed to open, for example I would see while going about my normal business. The images from the cams are also uploaded to my own web page every 15mins. I can see the whole day in 15min intervals. So, part of my thinking came from that.

I tried your 10s poll idea and that works too but I need a poll of 2sec to get an image every 10sec. I see in the log images being updated every 10sec until I turn the image update switch is off.

GarageCamImage changed from raw type (image/jpeg): 768000 bytes to raw type (image/jpeg): 768000 bytes

If leave it off then I need to switch it on manually to update the images. So that defeats the casual viewing. Turning it on/off automatically works eg when the garage door opens and every 15mins. Then the images are up to date without having to manually activate the update.

IMAGE_UPDATE_EVENTS=0, is needed to reduce traffic. I am not sure what =1 does yet. Readme wasn’t clear enough for a dummy :slight_smile:

Hi @matt1
Did you notice there is a new option in the openhab GA integration, which had been deployed to use Metadata now…
There is a trait for camera string available now…

String { ga="Camera" [ protocols="hls,dash" ] }

May this could come in hand for directly parsing a camera feed to a Google Hub/chromecast device.
I havn´t yet tried, as I´m still struggle getting my cam setup for video (ffmpeg)… Hopefully soon…

Just thought this might be worth mentioning.

@Kim_Andersen
Does your camera now go online with latest build and get snapshots? Yes I heard it was getting added soon, do you know if this requires anything to change on our server ends other than the string line? Is it purely an upgrade already done in the myopenhab cloud?

Hi @m4rk,

Your situation does challenge my thinking which I like, so thanks for the extra info. The next build the Image will update at the poll rate if it is 5 seconds or higher, under 5 seconds it is limited. The ipcamera.jpg method is not limited and is the most efficient way to get an image (if the camera can not serve the file directly).

I wish to stress the difference between the traffic on your internal network VS the traffic that potentially leaves and can head to your devices that are away from home. Having a shorter polling time does not mean it leaves the internal network. It only leaves if you have the picture showing on a UI and the picture is changing on the UI, so if you close the page showing the picture it stops or you can limit it by the refresh options in the sitemap.

There are a few approaches you can take to keep traffic to a minimum. Consider these…

  1. Set the poll time to 10 seconds. Then follow the method here using WebView and html files that refresh every 15 minutes in the html code. The UI can then be pulled down and let go in both the ios and android apps and it will refresh and give updated content at any time. In basic UI just use the browsers refresh ability (F5). Note you will need to use a VPN as WebView does not pass through myopenhab which is why you need a VPN or another method. Even though the internal server is updating every 10 seconds, the image only updates every 15 minutes or when you manually drag and let go.
  1. Change to using Pushover to send an animated GIF when your door is told to open or close. Pushover does not use the myopenhab server and the GIF is pretty small and can fast forward in time showing the door movement. Pushover also can be told to keep the last X messages so unlike email it keeps things tidy automatically and gives a history of the last X messages and gifs.

  2. Use the gif feature and display that in your sitemap with

Webview url="http://192.168.0.999:54321/ipcamera.gif" height=9

You can trigger its creation with motion alarms or the door closing can trigger it. WebView needs VPN to leave internal network.

  1. The way you were doing it is another way to change the refresh time “on demand” and perhaps I need to re-add some code to make it possible again. I just don’t like the idea of using a rule to toggle the switch.

  2. Using an Image item, you can use multiple links in your sitemap like the below, One has a 15minute refresh and a link opens to a page with a 10 second refresh. Fingers crossed I go the syntax right…

Image url="http://192.168.0.999:54321/ipcamera.jpg" refresh=900000
Text label="Camera 10 sec" icon="camera"{Image url="http://192.168.0.999:54321/ipcamera.jpg" refresh=10000}
  1. I just ran a test and mjpeg streams work with up to 9 seconds between picture changes. I could then change the refresh rate at any time inside the binding, a variable refresh so if an alarm goes off you can get higher rate that auto drops back to 9 seconds when the alarms stop, would be a cool feature but it seems to be limited at 9 seconds between pictures so for your use case not good enough.

No, still the same issue, so I´d let it rest untill I had more time to deal with it.
I will try to see if I can get it to work today. And hopefully I have figured out how to setup this ffmpeg… I honestly simply dont get it :frowning:

Just server side changes, so we dont have to change anything, except using metadata ofcouse…

If I manage to get my cam to work today, I´ll play with the new metadata as well…

Thanks Matt, I appreciate you spending some time on my use case. There is a lot to think about in your reply.

The basic idea was to make a easy to happen upon, top view, relatively up to date image without having to do anything like refresh, activate VPN, dig through sub sections, menus etc. I try to make this stuff as easy as possible to use usefully.

I have achieved this now with the current binding and will post the code for completeness at the bottom.

One thing I have noticed with higher refresh rates is my openHAB log filling up with

GarageCamImage changed from raw type (image/jpeg): 768000 bytes to raw type (image/jpeg): 768000 bytes

I try to avoid too much normal business stuff appearing in the logs because the problems and errors get easily missed.

I have three cameras. Here is the garage camera example

.thing

Thing ipcamera:HTTPONLY:001 "Garage camera" @ "Cams"
[
    IPADDRESS="192.168.x.x",
    USERNAME="x",
    PASSWORD="x",
    SNAPSHOT_URL_OVERRIDE="http://192.168.x.x/live/0/jpeg.jpg", 
    POLL_CAMERA_MS=2000,
    IMAGE_UPDATE_EVENTS=0,
    UPDATE_IMAGE=false,
    PORT=80
]

.items

Switch UpdateAllImages "Update images" <camera>
Switch IPCameraImageUpdate_Timer "Update IP camera images timer" <time> {expire="15m,command=ON"}
Image GarageCamImage "Garage camera image" <camera> { channel="ipcamera:HTTPONLY:001:image" }
Switch GarageCamUpdateImage "Get new image" <camera> { channel="ipcamera:HTTPONLY:001:updateImageNow" }

.rule
For manual activation of image update and automatic update every 15mins

rule 'Start updating camera images'
when 
    Item UpdateAllImages changed to ON or
    Item IPCameraImageUpdate_Timer changed to ON
then
   GarageCamUpdateImage.sendCommand(ON)
    TerraceCamUpdateImage.sendCommand(ON)
    PorchCamUpdateImage.sendCommand(ON)
    IPCameraImageUpdate_Timer.sendCommand(OFF)
    logInfo("Camera", "Updating started" )
    if (UpdateAllImages.state != ON) {
        if (ImageTimer === null) {
                ImageTimer = createTimer(now.plusSeconds(10)) [|
                        IPCameraImageUpdate_Timer.sendCommand(OFF)
                        GarageCamUpdateImage.sendCommand(OFF)
                        TerraceCamUpdateImage.sendCommand(OFF)
                        PorchCamUpdateImage.sendCommand(OFF)
                        logInfo("Camera", "Scheduled updating ended" )
                ImageTimer?.cancel()
                ImageTimer = null
            ]
        }
    }
end

For turning off manual activation of image updating

rule 'Stop updating camera images'
when 
    Item UpdateAllImages changed to OFF
then
    GarageCamUpdateImage.sendCommand(OFF)
    TerraceCamUpdateImage.sendCommand(OFF)
    PorchCamUpdateImage.sendCommand(OFF)
    logInfo("Camera", "Manual activated updating stopped" )
end

For garage door monitoring when commanded to Open or Close

rule 'Start garage camera image update while garage door is moving'
when
    Item GarageDoorMoving_Sensor changed to ON
then
        GarageCamUpdateImage.sendCommand(ON)
        logInfo("Camera" , 'Garage door moving >>> Garage image update started')
end

rule 'Stop garage camera image update  '
when
    Item GarageDoorMoving_Sensor changed to OFF
then
        GarageCamUpdateImage.sendCommand(OFF)
        logInfo("Camera" , 'Garage image update Stopped')
end

I am not sure if this needed but it makes sure the 15min timer is running at restart

rule "On restart"
when 
    System started
then
    logInfo("Startup" , "System startup time = " + now.toString("HH:mm dd-MM-yyyy"))
    IPCameraImageUpdate_Timer.sendCommand(OFF)
end

New build 2020-01-19 has these changes:

  • Now all the different mjpeg streams can be opened many times and the camera only sees 1 stream.
  • Snapshots can be generated from RTSP feed for httponly cameras. Only uses keyframes so depends how often your camera sends a keyframe as to how often it updates.
  • Changes for @m4rk so Image updates at poll rate if 5 seconds or more and updateimagenow should trigger an update. See the readme file on how to deal with the logs filling up with Image changes.
1 Like

Just downloaded and installed the latest version (as of today).
My Reolink RCL410 (added through PaperUI as Http only) went online and snapshot seems to work just fine, without using the override url…

I linked a few channels to items, and used PaperUI controlpanel to see whats happening:
Linked channels sofar:
Update the image (Switch). It works, but only if I set the option (1) in Snapshot/image update to always. Then I can turn on/off the image update… I believe this is not correct according to the text, the option (0) is said to update, only when the Switch is ON. (It doesnt).
Snapshot from camera - Works just fine. The image update every 2 seconds.
RTSP Url does not seem to show any stream in controlpanel. I´m not sure if it´s suppose to do that. I do have installed ffmpeg. But I have not changed or done any configuration. Just used the default.

Thats as far as I´ve got for now.

The newest version also doesn’t work for me.
I get the same error/warnings as in the older versions.

With the ONVIF Thing:

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

2020-01-19 18:28:31.237 [hingStatusInfoChangedEvent] - 'ipcamera:ONVIF:KGV' changed from INITIALIZING to ONLINE

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

2020-01-19 18:28:31.279 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - We got an ONVIF error400:<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns1="http://www.onvif.org/ver10/actionengine/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:ns10="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:ns11="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:ns12="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:ns13="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" xmlns:ns14="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:ns3="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:ns4="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ns5="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:ns6="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:ns7="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:ns8="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:ns9="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tls="http://www.onvif.org/ver10/display/wsdl" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><SOAP-ENV:Body><SOAP-ENV:Fault SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><SOAP-ENV:Code><SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value><SOAP-ENV:Subcode><SOAP-ENV:Value>ter:NotAuthorized</SOAP-ENV:Value></SOAP-ENV:Subcode></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">Sender not Authorized</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

And with the HTTPONLY Thing:

2020-01-19 18:25:25.825 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !!!! Camera has closed a channel 	URL: Cause reported is: {}

java.lang.ArrayIndexOutOfBoundsException: null

2020-01-19 18:25:47.868 [WARN ] [ing.ipcamera.handler.IpCameraHandler] - !!!! Camera has closed a channel 	URL: Cause reported is: {}

java.lang.ArrayIndexOutOfBoundsException: null

Try remove the override URL and use Http only.

Thanks. The warning message is gone.
But I don’t get an Image.

Try insert the RTSP URL.

Main Stream: rtsp://username:password@ip_address:554//h264Preview_01_main

Sub Stream: rtsp://username:password@ip_address:554//h264Preview_01_sub