From 9f5fbded23466292b9c7850c92aecf84f6d63043 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 20 Aug 2018 20:13:25 +1000 Subject: [PATCH] PIR alarm for HIK --- ESH-INF/thing/thing-types.xml | 115 +++++++++++------- .../ipcamera/IpCameraBindingConstants.java | 4 + .../ipcamera/handler/IpCameraHandler.java | 57 ++++++++- 3 files changed, 133 insertions(+), 43 deletions(-) diff --git a/ESH-INF/thing/thing-types.xml b/ESH-INF/thing/thing-types.xml index 3676357..1364a96 100644 --- a/ESH-INF/thing/thing-types.xml +++ b/ESH-INF/thing/thing-types.xml @@ -8,6 +8,8 @@ Use when your camera is not ONVIF compatible. + + @@ -22,8 +24,8 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - + + @@ -106,8 +108,8 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - + + @@ -206,14 +208,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - - - - - - - + + + + + + + + @@ -321,10 +323,10 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - - - + + + + @@ -393,7 +395,6 @@ The Image channel can be set to Update in a number of ways to help reduce networ - Use for all current HD FOSCAM Cameras as they support an API as well as ONVIF. @@ -404,7 +405,9 @@ The Image channel can be set to Update in a number of ways to help reduce networ - + + + @@ -433,14 +436,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - - - - - - - + + + + + + + + @@ -517,6 +520,7 @@ The Image channel can be set to Update in a number of ways to help reduce networ + @@ -554,10 +558,10 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - - - + + + + @@ -662,8 +666,8 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - + + @@ -761,14 +765,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ 1 - - - - - - - - + + + + + + + + @@ -897,6 +901,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ + + Switch + + PIR motion has been detected. + Motion + + + Switch @@ -951,7 +963,7 @@ The Image channel can be set to Update in a number of ways to help reduce networ By using this feature you can stop the camera from sending emails when you are actually home. Motion - + Switch @@ -979,5 +991,26 @@ The Image channel can be set to Update in a number of ways to help reduce networ You can use the cameras output to trigger a device like a burglar alarm. Alarm + + + Switch + + Turn the LED on and off. + Light + + + + Switch + + Turn automatic mode for the LED on and off. + + + + Switch + + Experimental, ignore this for now. + Camera + + diff --git a/src/main/java/org/openhab/binding/ipcamera/IpCameraBindingConstants.java b/src/main/java/org/openhab/binding/ipcamera/IpCameraBindingConstants.java index 8c336d2..0e242cf 100644 --- a/src/main/java/org/openhab/binding/ipcamera/IpCameraBindingConstants.java +++ b/src/main/java/org/openhab/binding/ipcamera/IpCameraBindingConstants.java @@ -71,4 +71,8 @@ public class IpCameraBindingConstants { public static final String CHANNEL_THRESHOLD_AUDIO_ALARM = "thresholdAudioAlarm"; public static final String CHANNEL_ACTIVATE_ALARM_OUTPUT = "activateAlarmOutput"; public static final String CHANNEL_EXTERNAL_ALARM_INPUT = "externalAlarmInput"; + public static final String CHANNEL_AUTO_LED = "autoLED"; + public static final String CHANNEL_ENABLE_LED = "enableLED"; + public static final String CHANNEL_PIR_ALARM = "pirAlarm"; + public static final String CHANNEL_STREAM_VIDEO = "streamVideo"; } diff --git a/src/main/java/org/openhab/binding/ipcamera/handler/IpCameraHandler.java b/src/main/java/org/openhab/binding/ipcamera/handler/IpCameraHandler.java index 579c3cb..9ccbbf9 100644 --- a/src/main/java/org/openhab/binding/ipcamera/handler/IpCameraHandler.java +++ b/src/main/java/org/openhab/binding/ipcamera/handler/IpCameraHandler.java @@ -770,6 +770,14 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception updateState(CHANNEL_THRESHOLD_AUDIO_ALARM, PercentType.valueOf("100")); } + //////////////// Infrared LED ///////////////////// + if (content.contains("0")) { + updateState(CHANNEL_ENABLE_LED, OnOffType.valueOf("OFF")); + } + if (content.contains("1")) { + updateState(CHANNEL_ENABLE_LED, OnOffType.valueOf("ON")); + } + if (content.contains("")) { ctx.close(); logger.debug("End of FOSCAM handler reached, so closing the channel to the camera now"); @@ -824,7 +832,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception } private class HikvisionHandler extends ChannelDuplexHandler { - byte lineCount, vmdCount, leftCount, takenCount, faceCount = 0; + byte lineCount, vmdCount, leftCount, takenCount, faceCount, pirCount = 0; void countDown() { if (lineCount > 1) { @@ -842,6 +850,9 @@ void countDown() { if (faceCount > 1) { faceCount--; } + if (pirCount > 1) { + pirCount--; + } } @Override @@ -891,6 +902,11 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception countDown(); } } + if (content.contains("PIR")) { + motionDetected(CHANNEL_PIR_ALARM); + pirCount = 5; + countDown(); + } if (content.contains("videoloss\r\ninactive")) { firstMotionAlarm = false; countDown(); @@ -1170,13 +1186,18 @@ public void handleCommand(ChannelUID channelUID, Command command) { case CHANNEL_ZOOM: getAbsoluteZoom(); break; - } return; // Return as we have handled the refresh command above and don't need to continue further. } // end of "REFRESH" switch (channelUID.getId()) { + case CHANNEL_STREAM_VIDEO: + if (snapshotUri != null) { + sendHttpGET("http://192.168.1.64/ISAPI/Streaming/channels/102/httppreview"); + } + break; + case CHANNEL_UPDATE_IMAGE_NOW: if (snapshotUri != null) { sendHttpGET(getCorrectUrlFormat(snapshotUri)); @@ -1184,6 +1205,38 @@ public void handleCommand(ChannelUID channelUID, Command command) { break; + case CHANNEL_ENABLE_LED: + + switch (thing.getThingTypeUID().getId()) { + case "FOSCAM": + // Disable the auto mode first + sendHttpGET("/cgi-bin/CGIProxy.fcgi?cmd=setInfraLedConfig&mode=1&usr=" + username + "&pwd=" + + password); + updateState(CHANNEL_AUTO_LED, OnOffType.valueOf("OFF")); + if ("ON".equals(command.toString())) { + sendHttpGET("/cgi-bin/CGIProxy.fcgi?cmd=openInfraLed&usr=" + username + "&pwd=" + password); + } else { + sendHttpGET( + "/cgi-bin/CGIProxy.fcgi?cmd=closeInfraLed&usr=" + username + "&pwd=" + password); + } + break; + } + break; + + case CHANNEL_AUTO_LED: + switch (thing.getThingTypeUID().getId()) { + case "FOSCAM": + if ("ON".equals(command.toString())) { + sendHttpGET("/cgi-bin/CGIProxy.fcgi?cmd=setInfraLedConfig&mode=0&usr=" + username + "&pwd=" + + password); + } else { + sendHttpGET("/cgi-bin/CGIProxy.fcgi?cmd=setInfraLedConfig&mode=1&usr=" + username + "&pwd=" + + password); + } + break; + } + break; + case CHANNEL_THRESHOLD_AUDIO_ALARM: switch (thing.getThingTypeUID().getId()) {