Skip to content

Commit 14a334f

Browse files
Skinahdigitaldan
authored andcommitted
[ipcamera] Add motion and alarm support for Axis branded cameras (openhab#17419)
* Add support for Axis motion detection Signed-off-by: Matthew Skinner <matt@pcmus.com>
1 parent 4a42a47 commit 14a334f

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

  • bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif

bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public enum RequestType {
129129
private String imagingXAddr = "http://" + ipAddress + "/onvif/device_service";
130130
private String ptzXAddr = "http://" + ipAddress + "/onvif/ptz_service";
131131
public String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service";
132+
public String subscriptionId = "";
132133
private boolean isConnected = false;
133134
private int mediaProfileIndex = 0;
134135
private String rtspUri = "";
@@ -340,7 +341,12 @@ public void processReply(String message) {
340341
} else if (message.contains("CreatePullPointSubscriptionResponse")) {
341342
supportsEvents = true;
342343
subscriptionXAddr = Helper.fetchXML(message, "SubscriptionReference>", "Address>");
343-
logger.debug("subscriptionXAddr={}", subscriptionXAddr);
344+
int start = message.indexOf("<dom0:SubscriptionId");
345+
int end = message.indexOf("</dom0:SubscriptionId>");
346+
if (start > -1 && end > start) {
347+
subscriptionId = message.substring(start, end + 22);
348+
}
349+
logger.debug("subscriptionXAddr={} subscriptionId={}", subscriptionXAddr, subscriptionId);
344350
sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
345351
} else if (message.contains("GetStatusResponse")) {
346352
processPTZLocation(message);
@@ -532,7 +538,12 @@ public void sendOnvifRequest(RequestType requestType, String xAddr) {
532538
+ encodeBase64(nonce)
533539
+ "</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
534540
+ dateTime + "</Created></UsernameToken></Security>";
535-
headers = "<s:Header>" + security + headerTo + "</s:Header>";
541+
542+
if (requestType.equals(RequestType.PullMessages) || requestType.equals(RequestType.Renew)) {
543+
headers = "<s:Header>" + security + headerTo + subscriptionId + "</s:Header>";
544+
} else {
545+
headers = "<s:Header>" + security + headerTo + "</s:Header>";
546+
}
536547
} else {// GetSystemDateAndTime must not be password protected as per spec.
537548
headers = "";
538549
}
@@ -674,10 +685,12 @@ public void eventRecieved(String eventMessage) {
674685
ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
675686
}
676687
break;
688+
case "RuleEngine/tnsaxis:VMD3/vmd3_video_1":
689+
case "RuleEngine/MotionRegionDetector/Motion":
677690
case "VideoSource/MotionAlarm":
678-
if ("true".equals(dataValue)) {
691+
if ("true".equals(dataValue) || "1".equals(dataValue)) {
679692
ipCameraHandler.motionDetected(CHANNEL_MOTION_ALARM);
680-
} else if ("false".equals(dataValue)) {
693+
} else if ("false".equals(dataValue) || "0".equals(dataValue)) {
681694
ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
682695
}
683696
break;
@@ -709,10 +722,11 @@ public void eventRecieved(String eventMessage) {
709722
ipCameraHandler.changeAlarmState(CHANNEL_TAMPER_ALARM, OnOffType.OFF);
710723
}
711724
break;
725+
case "Device/tnsaxis:HardwareFailure/StorageFailure":
712726
case "Device/HardwareFailure/StorageFailure":
713-
if ("true".equals(dataValue)) {
727+
if ("true".equals(dataValue) || "1".equals(dataValue)) {
714728
ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.ON);
715-
} else if ("false".equals(dataValue)) {
729+
} else if ("false".equals(dataValue) || "0".equals(dataValue)) {
716730
ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.OFF);
717731
}
718732
break;
@@ -728,9 +742,9 @@ public void eventRecieved(String eventMessage) {
728742
case "VideoSource/GlobalSceneChange/AnalyticsService":
729743
case "VideoSource/GlobalSceneChange/ImagingService":
730744
case "VideoSource/GlobalSceneChange/RecordingService":
731-
if ("true".equals(dataValue)) {
745+
if ("true".equals(dataValue) || "1".equals(dataValue)) {
732746
ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.ON);
733-
} else if ("false".equals(dataValue)) {
747+
} else if ("false".equals(dataValue) || "0".equals(dataValue)) {
734748
ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.OFF);
735749
}
736750
break;

0 commit comments

Comments
 (0)