Skip to content

Commit

Permalink
PIR alarm for HIK
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt authored and Matt committed Aug 20, 2018
1 parent 1b7eda2 commit 9f5fbde
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 43 deletions.
115 changes: 74 additions & 41 deletions ESH-INF/thing/thing-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<description>Use when your camera is not ONVIF compatible.</description>
<channels>
<channel id="updateImageNow" typeId="updateImageNow" />
<channel id="streamVideo" typeId="streamVideo" />

<channel id="image" typeId="image" />
<channel id="imageurl" typeId="imageurl" />
</channels>
Expand All @@ -22,8 +24,8 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image(1)</option>
</options>
</parameter>

Expand Down Expand Up @@ -106,8 +108,8 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
</options>
</parameter>

Expand Down Expand Up @@ -206,14 +208,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="2">Start Motion Alarm</option>
<option value="3">Start Audio Alarm</option>
<option value="23">Start of Motion and Audio Alarms</option>
<option value="4">During Motion Alarm</option>
<option value="5">During Audio Alarm</option>
<option value="45">During Motion and Audio Alarms</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
<option value="2">Start Motion Alarm (2)</option>
<option value="3">Start Audio Alarm (3)</option>
<option value="23">Start of Motion and Audio Alarms (23)</option>
<option value="4">During Motion Alarm (4)</option>
<option value="5">During Audio Alarm (5)</option>
<option value="45">During Motion and Audio Alarms (45)</option>
</options>
</parameter>

Expand Down Expand Up @@ -321,10 +323,10 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="2">Start Motion Alarm</option>
<option value="4">During Motion Alarm</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
<option value="2">Start Motion Alarm (2)</option>
<option value="4">During Motion Alarm (4)</option>
</options>
</parameter>

Expand Down Expand Up @@ -393,7 +395,6 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</config-description>
</thing-type>


<thing-type id="FOSCAM">
<label>"FOSCAM" IP camera with ONVIF and API support.</label>
<description>Use for all current HD FOSCAM Cameras as they support an API as well as ONVIF.</description>
Expand All @@ -404,7 +405,9 @@ The Image channel can be set to Update in a number of ways to help reduce networ
<channel id="motionAlarm" typeId="motionAlarm" />
<channel id="enableAudioAlarm" typeId="enableAudioAlarm" />
<channel id="audioAlarm" typeId="audioAlarm" />
<channel id="thresholdAudioAlarm" typeId="thresholdAudioAlarm" />
<channel id="thresholdAudioAlarm" typeId="thresholdAudioAlarm" />
<channel id="autoLED" typeId="autoLED" />
<channel id="enableLED" typeId="enableLED" />
<channel id="pan" typeId="pan" />
<channel id="tilt" typeId="tilt" />
<channel id="zoom" typeId="zoom" />
Expand Down Expand Up @@ -433,14 +436,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="2">Start Motion Alarm</option>
<option value="3">Start Audio Alarm</option>
<option value="23">Start of Motion and Audio Alarms</option>
<option value="4">During Motion Alarm</option>
<option value="5">During Audio Alarm</option>
<option value="45">During Motion and Audio Alarms</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
<option value="2">Start Motion Alarm (2)</option>
<option value="3">Start Audio Alarm (3)</option>
<option value="23">Start of Motion and Audio Alarms (23)</option>
<option value="4">During Motion Alarm (4)</option>
<option value="5">During Audio Alarm (5)</option>
<option value="45">During Motion and Audio Alarms (45)</option>
</options>
</parameter>

Expand Down Expand Up @@ -517,6 +520,7 @@ The Image channel can be set to Update in a number of ways to help reduce networ
<channel id="image" typeId="image"/>
<channel id="enableMotionAlarm" typeId="enableMotionAlarm"/>
<channel id="motionAlarm" typeId="motionAlarm"/>
<channel id="pirAlarm" typeId="pirAlarm"/>
<channel id="enableLineCrossingAlarm" typeId="enableLineCrossingAlarm"/>
<channel id="lineCrossingAlarm" typeId="lineCrossingAlarm"/>
<channel id="itemLeft" typeId="itemLeft"/>
Expand Down Expand Up @@ -554,10 +558,10 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="2">Start Motion Alarm</option>
<option value="4">During Motion Alarm</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
<option value="2">Start Motion Alarm (2)</option>
<option value="4">During Motion Alarm (4)</option>
</options>
</parameter>

Expand Down Expand Up @@ -662,8 +666,8 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
</options>
</parameter>

Expand Down Expand Up @@ -761,14 +765,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ
</description>
<default>1</default>
<options>
<option value="0">Never Update Image</option>
<option value="1">Always Update Image</option>
<option value="2">Start Motion Alarm</option>
<option value="3">Start Audio Alarm</option>
<option value="23">Start of Motion and Audio Alarms</option>
<option value="4">During Motion Alarm</option>
<option value="5">During Audio Alarm</option>
<option value="45">During Motion and Audio Alarms</option>
<option value="0">Never Update Image (0)</option>
<option value="1">Always Update Image (1)</option>
<option value="2">Start Motion Alarm (2)</option>
<option value="3">Start Audio Alarm (3)</option>
<option value="23">Start of Motion and Audio Alarms (23)</option>
<option value="4">During Motion Alarm (4)</option>
<option value="5">During Audio Alarm (5)</option>
<option value="45">During Motion and Audio Alarms (45)</option>
</options>
</parameter>

Expand Down Expand Up @@ -897,6 +901,14 @@ The Image channel can be set to Update in a number of ways to help reduce networ
<state readOnly="true" />
</channel-type>

<channel-type id="pirAlarm">
<item-type>Switch</item-type>
<label>PIR Alarm</label>
<description>PIR motion has been detected.</description>
<category>Motion</category>
<state readOnly="true" />
</channel-type>

<channel-type id="lineCrossingAlarm">
<item-type>Switch</item-type>
<label>Line Crossing Alarm</label>
Expand Down Expand Up @@ -951,7 +963,7 @@ The Image channel can be set to Update in a number of ways to help reduce networ
<description>By using this feature you can stop the camera from sending emails when you are actually home.</description>
<category>Motion</category>
</channel-type>

<channel-type id="enableLineCrossingAlarm">
<item-type>Switch</item-type>
<label>Enable/Disable the Line Crossing Alarm</label>
Expand Down Expand Up @@ -979,5 +991,26 @@ The Image channel can be set to Update in a number of ways to help reduce networ
<description>You can use the cameras output to trigger a device like a burglar alarm.</description>
<category>Alarm</category>
</channel-type>

<channel-type id="enableLED">
<item-type>Switch</item-type>
<label>Enable/Disable the Infrared LED</label>
<description>Turn the LED on and off.</description>
<category>Light</category>
</channel-type>

<channel-type id="autoLED">
<item-type>Switch</item-type>
<label>Auto control the Infrared LED</label>
<description>Turn automatic mode for the LED on and off.</description>
</channel-type>

<channel-type id="streamVideo">
<item-type>Switch</item-type>
<label>Enable/Disable the Video streaming (experimental)</label>
<description>Experimental, ignore this for now.</description>
<category>Camera</category>
</channel-type>


</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("<infraLedState>0</infraLedState>")) {
updateState(CHANNEL_ENABLE_LED, OnOffType.valueOf("OFF"));
}
if (content.contains("<infraLedState>1</infraLedState>")) {
updateState(CHANNEL_ENABLE_LED, OnOffType.valueOf("ON"));
}

if (content.contains("</CGI_Result>")) {
ctx.close();
logger.debug("End of FOSCAM handler reached, so closing the channel to the camera now");
Expand Down Expand Up @@ -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) {
Expand All @@ -842,6 +850,9 @@ void countDown() {
if (faceCount > 1) {
faceCount--;
}
if (pirCount > 1) {
pirCount--;
}
}

@Override
Expand Down Expand Up @@ -891,6 +902,11 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
countDown();
}
}
if (content.contains("<eventType>PIR</eventType>")) {
motionDetected(CHANNEL_PIR_ALARM);
pirCount = 5;
countDown();
}
if (content.contains("<eventType>videoloss</eventType>\r\n<eventState>inactive</eventState>")) {
firstMotionAlarm = false;
countDown();
Expand Down Expand Up @@ -1170,20 +1186,57 @@ 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));
}

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()) {
Expand Down

0 comments on commit 9f5fbde

Please sign in to comment.