Camera refresh frequency

I have a couple of Wifi cameras set up and working fine with the ipCamera binding.

I would like to reduce the refresh frequency of these from 2s to 10s to reduce server load/network traffic.

I have changed my sitemap entries so that the image refresh setting is 10000.

The camera still insist on updating every 2s (I can see this in the log). I have tried re-starting openHAB etc. but it insists on refreshing every 2s - at least I’m assuming that it is refreshing, unless the entries in the log (below) are misleading?

Log excerpt:

2020-01-21 22:19:16.369 [vent.ItemStateChangedEvent] - GardenCameraImage changed from raw type (image/jpeg): 44378 bytes to raw type (image/jpeg): 44367 bytes

2020-01-21 22:19:16.504 [vent.ItemStateChangedEvent] - KitchenCameraImage changed from raw type (image/jpeg): 55012 bytes to raw type (image/jpeg): 55002 bytes

2020-01-21 22:19:18.353 [vent.ItemStateChangedEvent] - GardenCameraImage changed from raw type (image/jpeg): 44367 bytes to raw type (image/jpeg): 44412 bytes

2020-01-21 22:19:18.466 [vent.ItemStateChangedEvent] - KitchenCameraImage changed from raw type (image/jpeg): 55002 bytes to raw type (image/jpeg): 54949 bytes

2020-01-21 22:19:20.348 [vent.ItemStateChangedEvent] - GardenCameraImage changed from raw type (image/jpeg): 44412 bytes to raw type (image/jpeg): 44391 bytes

I noticed that the cameras have a ‘Snapshot/Image’ setting named ‘Time in milliseconds between checking camera states and fetching a JPG/Image.’. I have tried increasing this to 10000, but it doesn’t make any difference and seems to reset itself back to 2000.

Any ideas anyone?

Try stopping OH and cleaning the cache after making the config change.

sudo systemctl stop openhab2

sudo openhab-cli clean-cache

sudo systemctl start openhab2

After this OH will take a few mins to fully start back up so please allow 3 to 5 minuets before panicking. :grin:

I can think of 3 reasons, reason 2 is most likely the case…

  1. You used textual config which locks the values and you are trying to adjust them in PaperUI. Logs should give u clues this is happening.
  2. Your using a RTSP feed to create the snapshots from which is a new feature and what your seeing is a side effect. If your camera sends a key frame every 2 seconds then the snapshot will be created every 2 seconds from the rtsp stream. More coding is needed to fix this and if your worried about network traffic and this is the case then the snapshots are less then the rtsp stream running :slight_smile:
  3. You have an item that is asking for ‘ipcamera.jpg’ at a refresh of 2 seconds. If you ask for the jpg it fetches a new one on demand regardless of the poll rate. This is a feature.

@matt1 Thanks for the suggestions.

I’m using PaperUI/HABmin for the Things, all my Items are in text files.

My Image Items simply link to the camera ‘:image’ channel. One is a Foscam and I’m using a simple HTTP JPG snapshot (ipcamera:HTTPONLY), the other is a newer ONVIF (ipcamera:ONVIF).

Image GardenCameraImage { channel="ipcamera:ONVIF:GardenCamera:image" }
Image KitchenCameraImage { channel="ipcamera:HTTPONLY:KitchenCamera:image" }

Please can you clarify what the setting ‘Snapshot/Image’ config setting named ‘Time in milliseconds between checking camera states and fetching a JPG/Image.’ does? This is set to 2000ms at the moment, and as I mentioned above it seems to jump back to that if I set it higher. To me, it doesn’t really look like a polling rate from its description though.

I have double checked all references to my cameras in my sitemaps; all are ‘refresh=10000’.

        Text label="Camera" icon="camera"  {
            Image item=GardenCameraImage refresh=10000
        }
        Text label="Camera" icon="camera"  {
            Image item=KitchenCameraImage refresh=10000
        }

Let me check for a bug tonight as it has been a while since I setup a camera from scratch in Paper UI as I use things files. If you use a things file it will change as I use 1000ms for all mine.

If you can not change the value that is the issue.

As @H102 suggested try clearing cache but make sure you reboot twice, I find two tones is needed to regenerate the cache and reboot cleanly with 2.5 stable.

@matt1 OK thanks for that. I’ll also try the cache clearing later as suggested by @H102.

I got to the bottom of this.

It seems that, even though I use PaperUI/HABmin for all my other Things, for some reason I had set up my Cameras using text files.
I modified the POLL_CAMERA_MS in the thing file and everything works now expected.
Apologies for the misinformation! :anguished:
One thing I did notice though is that I get the following Exception when the camera handler starts:

2020-01-27 13:15:54.916 [INFO ] [ing.ipcamera.handler.IpCameraHandler] - IP Camera at 192.168.1.203 is now online.

2020-01-27 13:15:54.938 [ERROR] [ing.ipcamera.handler.IpCameraHandler] - Exception occured starting the new streaming server:{}

java.net.BindException: Address already in use

	at sun.nio.ch.Net.bind0(Native Method) ~[?:1.8.0_222]

	at sun.nio.ch.Net.bind(Net.java:433) ~[?:1.8.0_222]

	at sun.nio.ch.Net.bind(Net.java:425) ~[?:1.8.0_222]

	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:1.8.0_222]

	at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130) ~[?:?]

	at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:563) ~[?:?]

	at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1332) ~[?:?]

	at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:488) ~[?:?]

	at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:473) ~[?:?]

	at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:984) ~[?:?]

	at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:259) ~[?:?]

	at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366) ~[?:?]

	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[?:?]

	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) ~[?:?]

	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495) ~[?:?]

	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) ~[?:?]

	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[?:?]

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

It doesn’t appear to cause a noticeable problem - all my 3 camera are working OK.

Here are my Things for reference:

Thing ipcamera:HTTPONLY:KitchenCamera "Kitchen Camera" @ "Cameras"
[
    IPADDRESS="192.168.1.207",
    POLL_CAMERA_MS=10000,
    SERVER_PORT=8090,
    USERNAME="<redacted>",
    PASSWORD="<redacted>",
    IP_WHITELIST="DISABLE",
    IMAGE_UPDATE_EVENTS=1,
    UPDATE_IMAGE=true,
    SNAPSHOT_URL_OVERRIDE="http://192.168.1.207:8090/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=<redacted>&pwd=<redacted>&"
]

Thing ipcamera:ONVIF:GardenCamera "Garden Camera" @ "Cameras"
[
    IPADDRESS="192.168.1.218",
    POLL_CAMERA_MS=10000,
    ONVIF_PORT=80,
    USERNAME="<redacted>",
    PASSWORD="<redacted>",
    IP_WHITELIST="DISABLE",
    IMAGE_UPDATE_EVENTS=1,
    UPDATE_IMAGE=true,
    SNAPSHOT_URL_OVERRIDE="http://192.168.1.218/tmpfs/auto.jpg"
]

Thing ipcamera:HTTPONLY:3DPrinterCamera "3D Printer Camera" @ "Cameras"
[
    IPADDRESS="192.168.1.203",
    POLL_CAMERA_MS=10000,
    SERVER_PORT=8080,
    IP_WHITELIST="DISABLE",
    IMAGE_UPDATE_EVENTS=1,
    UPDATE_IMAGE=true,
    SNAPSHOT_URL_OVERRIDE="http://192.168.1.203:8080/?action=snapshot"
]

There’s the problem, Openhab uses that port already, choose another one. Your the second person to not understand what the error means so I will look to capture this and present a nicer error that is easier to understand.

I recommend you make that false or you will soon be posting about OOME errors. With 10 second updates from three cameras you probably will get away with it. See readme file for how to get a picture without using the Image channel.

@matt1 Thanks for the heads up.
As it happens, I was getting OOM errors which seemed to start once I added the 3rd camera.

I see from this that it is possible to reference a camera snaphot URL directly in a sitemap using:

Image url="<camera_snaphot_url>" refresh=10000

I wasn’t aware of this functionality. This worked OK for all my cameras.

Yes that is a better way as the image is only updated when someone has the UI open. But I still prefer not to use an image element at all, the video element is a better match for content that changes often and is large in size.

I set up one of my HTTP only cameras using a Video element:

Video url="http://192.168.1.207:8090/cgi-bin/CGIStream.cgi?cmd=GetMJStream&usr=<username>&pwd=<password>&" encoding="mjpeg"

That works fine too.

My ONVIF camera doesn’t appear to have a native HTTP video stream though, only an RTSP stream; and these don’t appear to be able to be displayed directly in a sitemap (correct me if I’m wrong). So it looks like to use that I would need to either use your binding to do the conversion, or use ffmpeg to do a background conversion, both of which are presumably too CPU/memory intensive for use on a Raspberry Pi 4?

Since my cameras give lower resolution in mjpeg from the camera directly, I prefer the bindings snapshots.mjpeg feature as it is created from the cameras snapshots which are high resolution and don’t use much cpu power. That should work on your cameras that don’t have mjpeg. Lots of options to choose from.