IpCamera: New IP Camera Binding

I use SSD drive for openhab.
I´m not afraid of the backup. I know how to make backups.
I´m afraid experience the same as with Grafana. It worked fine for quite a while, then I updated openhab to 2.4, and hell broke loose with openhab/java restarted several times a day, (Java crashed and restarted openhab). But it only happened randomly. I could render one chart fine, and sometimes two, but often two crashed java, and three charts for certain crashed Java. It was a hell finding the reason, and required deeper Linux knowledged, which I havn´t got. So it took me quite a while to figure this one.

Thats the experience I´m afraid of using rpi and pushing it too hard. But I´m tempted to give it a try as I would rather want HLS streaming than image snapshots… Or perhaps animated gif´s. As you can see in another thread, my plan is to cast this to my Google Home Hub.

When I install the latest binding (06.09.2019) I get this error:

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

2019-06-11 18:50:25.160 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.binding.ipcamera-2.5.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.ipcamera [295]
  Unresolved requirement: Import-Package: io.netty.bootstrap; version="[4.1.0,5.0.0)"
	at org.eclipse.osgi.container.Module.start(Module.java:444) ~[?:?]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [10:org.apache.felix.fileinstall:3.6.4]

In the zip file I downloaded, there are 8 .jar files beside the binding… Are they all suppose to be copied into the addons ?

Got my module today, just got it working with arduino and your binding to just dial into my Wifi and provide regular MJPEG images. Will polish the code (and remove Wifi credentials :wink: ) and publish tomorrow I think. Adding Wifi Manager will be in a later time but on my agenda.

Nifty little thing - great small display.

… this enables to use deep sleep - so this thing will be on coin cell for ages.

Yes all must be in the addons.
You will also need to clear tmp and cache folders.
If you have not done textual config (things file) you need to delete and readd the camera.
There are breaking changes to be aware of especially if you override urls with textual config.

Using the search on this thread will answer these for you.

@Sascha_
Very Cool let me know how it goes.

@matt1: can i somehow display these prefetch images through use of a URL? For me the new animated gif creation (pre- and postroll) work perfectly; i send that to my phone. But i want to display camera images on my kodi systems using Security camera overlay. This uses a URL for image retrieval refreshed every second. As i have 3 Kodi streamers and am using image refresh every second for animated image creation, i get too much calls to my camera and the images are not dispayed. If i can serve the images already retrieved by your binding this will take out any additional stress on the camera; openhab will serve these images to all 3 streamers.

Not currently but it would be possible for the binding to pass them on without being saved to disk if the feature was added. I already do a similar thing for the mjpeg stream for similar reasons.

I would normally say use the camera to serve the files directly but you gave a good description of why that won’t work.

This method may work if you save the file to the HTML folder and use openhabs serving ability.

Just to be clear about the way it works now; does the image channel save the image to disk every poll interval? it doesn’t seem to do that. It would be a welcome addition to have a switch channel available to be able to to just that. If the switch is on the fetched image is also saved to the FFMPEG_OUTPUT location (and thus overwritten every poll), if it is off it behaves as current behaviour. THis way i can save the images to the opehad html folder for some seconds as long as the kodi streamers show the camera overlay…

No the binding tries to keep loads on the openhab server as low as possible and as most users have a raspberry pi with possibly a sd card I don’t believe that is a good idea. The way would be to allow this url to be used which keeps things consistent with how the rest of the binding works.
Openhabip:54321/ipcamera.jpg
Then it only places a load on the server when kodi asks for the file and it does not use the disk, only ram.

Could you do a guide on how u setup kodi to do the overlay?

Not to spam this topic, I’ve created a seperate thread for my development

1 Like

The Kodi Security Cam Overlay can be found here. After installation you can configure up to 4 camera feeds (image URL) and some other stuff like refresh time etc.

within openhab i created a rule which is used to send an animated gif to my phone with pushover, and display image feed onto kodi:

rule "DoorBell"
when
    Item Doorbell changed to ON
then
    if (FrontDoorButtonPressed.state != ON) {
        FrontDoorCreateGif.sendCommand(ON)
        FrontDoorButtonPressed.sendCommand(ON)
        var String content = '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam"},"id":"1"}'
	    sendHttpPostRequest("http://192.168.x.x:8080/jsonrpc",'application/json',content)
        sendHttpPostRequest("http://192.168.x.x:8080/jsonrpc",'application/json',content)
        sendHttpPostRequest("http://192.168.x.x:8080/jsonrpc",'application/json',content)
    }
end

So it would be very welcome the ipcamera binding could host a snapshot available through an url so i have to configure one URL only, not having multiple requests to the camera.

You could always mount a tmpfs directory and just store it there.

Thanks for your amazing work on this, Matt. I recently rebuilt my OH server which had been upgraded from 2.0->2.1->2.2->2.3-2.4 and was frequently crashing due to running out of Java heap space so I took the opportunity to upgrade to the latest version of your binding.

I’m using several Hikvision 2085 cameras and I noticed that the snapshot capture URL override and the stream URL override needed to be filled in the latest version. I’m fairly sure I didn’t need to specify these with the earlier version of the binding. I say I’m fairly sure but I have a bad memory and never take notes when I configure stuff…

I also got the GIF capture working and can see a ipcamera.gif file in the tmpfs directory. How can I use this file with Telegram. I already have a rule that sends a couple of snapshots:

    rule "Send telegram with fixed message when front door camera intrusion detected"
when
    Item CameraFrontDoor_IntrusionAlarm changed from OFF to ON
then
    logInfo("Dev", "Front door camera intrusion detected.")
    CameraFrontDoor_UpdateTheImage.sendCommand(ON)
	AVTVLGWebOSTVOLED55B6V_1_Toast.sendCommand("Front door camera intrusion detected")
    sendTelegram("Bot", "Front door camera intrusion detected")
    Thread::sleep(100)
    CameraFrontDoor_UpdateTheImage.sendCommand(OFF)
    var String base64Image0 = CameraFrontDoor_SnapshotFromCamera.state.toFullString
    sendTelegramPhoto("Bot", base64Image0, "Intrusion detected at front door")
    Thread::sleep(1000)
    CameraFrontDoor_UpdateTheImage.sendCommand(ON)
    Thread::sleep(100)
    CameraFrontDoor_UpdateTheImage.sendCommand(OFF)
    var String base64Image1 = CameraFrontDoor_SnapshotFromCamera.state.toFullString
    sendTelegramPhoto("Bot", base64Image1, "Intrusion detected at front door")
end

The line

var String base64Image1 = CameraFrontDoor_SnapshotFromCamera.state.toFullString

gets the snapshot into an item that can be passed to the Telegram binding. How can I do the same thing with the GIF file?

The documentation looks very good… See this link as it could be done by the file or by the URL. NOTE: I have not done it yet so the below rule is just a guess.

rule "Send telegram with local image and caption"
when
    Item CameraFrontDoor_CreateGif changed from ON to OFF
then
    sendTelegramPhoto("bot1", "file:///path/to/local/ipcamera.gif", "sent from openHAB")
end

I had no idea the Telegram binding could access files. Thanks for the info.

I’ve updated my rule to these two:

rule "Create front door camera GIF when front door camera intrusion detected"
when
    Item CameraFrontDoor_IntrusionAlarm changed from OFF to ON
then
    logInfo("Dev", "Front door camera intrusion detected, triggering camera GIF creation...")
    CameraFrontDoor_CreateAnAnimatedGIF.sendCommand(ON)
end

rule "Send front door camera GIF via Telegram"
when
    Item CameraFrontDoor_CreateAnAnimatedGIF changed from ON to OFF
then

sendTelegram("Bot", "Front door camera intrusion detected")

sendTelegramPhoto("Bot", "file:///etc/openhab2/html/tmpfs/ipcamera.gif", "Intrusion detected at front door, GIF sent")

end

This works as far as sending an image to Telegram but it’s not animated. The ipcamera.gif file on the OH server is around 800k but the file saved to the gallery on my phone is about 50k. This must be a limitation of the Telegram binding, maybe it’s pulling only the first frame from the GIF and sending that?

Have you managed to send animated GIF files via Telegram? Maybe I’m missing something important…

It is possible the Telegram binding/action does not support the feature. The telegram API does support the sending of animations and also mp4 video files which the binding could be made to support if it does not already, see here…

I know people are doing it with Pushover and having a moving picture in the push messages. See if you can ask this question to the telegram binding maintainer @ZzetT (?) if it is supported and if not if it can be added for both gif and mp4.

If you are running a PI the default amount of memory Openhab can access is way too small in my opinion when all the device is doing is running Openhab and no other major system processes. By default I think the heap size is 1/4 of the ram in your system and that is all Openhab can use unless you make the change in this post. You need to leave some ram for Linux and other processes like Mosquitto that do not run in the Java virtual machine.

I did make a change recently due to a user request as their camera did not work with ISAPI urls, can you confirm this is the issue by trying these two in a web browser please? Ip of your camera comes first. Otherwise it may be the NVR channel is set wrong and overriding the url removes the effect of the nvr setting.

/Streaming/channels/101/picture

/ISAPI/Streaming/channels/101/picture

1 Like

New build 2019-06-22 has these changes:

  • Binding can now respond to requests for a current snapshot ipcamera.jpg if you use this url: http://192.168.xxx.xxx:54321/ipcamera.jpg
    @posixx you requested this feature, let me know if it fixes your use case.
    @Kim_Andersen this feature should make casting a static picture very easy if it does not work direct from a camera.

  • Changes to Instar to give correct default ONVIF port and snapshot url.

  • Huge clean up of the code that means all cameras were touched. This was to make the binding closer to merge to the project and make it easier to maintain the code. Look for bugs and any changes in performance.

1 Like

@matt1 tnx for the feature. i will install an test tomorrow. To prepare for that; how does this url determine which ipcamera to use for the shapshot? I have 7 camera’s and need a way to select the frontdoor camera?

Each camera will have its own port that the binding is serving the files on. So just change the number 54321 to something unique for each camera.

Ok, which configuation parameter is used for this port? It seems i’m not able to determine which one…

EDIT: oh i think it’s the default port configured in things file. I get an image when i open this URL but it’s the animated image from the last animated gif creation. I would expect the same image as the image channel content (ipcamera:HIKVISION:FrontDoor:image)…

EDIT2: Sorry, i used ipcamera.gif which is the animated gif ofcourse. using ipcamera.jpg gives me the current snapshot! Looks very gooed will try on my kodi systems tomorrow.