From: Matthew Skinner Date: Sun, 15 Sep 2024 20:48:00 +0000 (+1000) Subject: [ipcamera] Add motion and alarm support for Axis branded cameras (#17419) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=3930bffd09c0ec78571478dc0b94172071cb62a9;p=openhab-addons.git [ipcamera] Add motion and alarm support for Axis branded cameras (#17419) * Add support for Axis motion detection Signed-off-by: Matthew Skinner --- diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java index 0c27eabcd9..daab2b30d4 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java @@ -129,6 +129,7 @@ public class OnvifConnection { private String imagingXAddr = "http://" + ipAddress + "/onvif/device_service"; private String ptzXAddr = "http://" + ipAddress + "/onvif/ptz_service"; public String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service"; + public String subscriptionId = ""; private boolean isConnected = false; private int mediaProfileIndex = 0; private String rtspUri = ""; @@ -340,7 +341,12 @@ public class OnvifConnection { } else if (message.contains("CreatePullPointSubscriptionResponse")) { supportsEvents = true; subscriptionXAddr = Helper.fetchXML(message, "SubscriptionReference>", "Address>"); - logger.debug("subscriptionXAddr={}", subscriptionXAddr); + int start = message.indexOf(""); + if (start > -1 && end > start) { + subscriptionId = message.substring(start, end + 22); + } + logger.debug("subscriptionXAddr={} subscriptionId={}", subscriptionXAddr, subscriptionId); sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr); } else if (message.contains("GetStatusResponse")) { processPTZLocation(message); @@ -532,7 +538,12 @@ public class OnvifConnection { + encodeBase64(nonce) + "" + dateTime + ""; - headers = "" + security + headerTo + ""; + + if (requestType.equals(RequestType.PullMessages) || requestType.equals(RequestType.Renew)) { + headers = "" + security + headerTo + subscriptionId + ""; + } else { + headers = "" + security + headerTo + ""; + } } else {// GetSystemDateAndTime must not be password protected as per spec. headers = ""; } @@ -674,10 +685,12 @@ public class OnvifConnection { ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM); } break; + case "RuleEngine/tnsaxis:VMD3/vmd3_video_1": + case "RuleEngine/MotionRegionDetector/Motion": case "VideoSource/MotionAlarm": - if ("true".equals(dataValue)) { + if ("true".equals(dataValue) || "1".equals(dataValue)) { ipCameraHandler.motionDetected(CHANNEL_MOTION_ALARM); - } else if ("false".equals(dataValue)) { + } else if ("false".equals(dataValue) || "0".equals(dataValue)) { ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM); } break; @@ -709,10 +722,11 @@ public class OnvifConnection { ipCameraHandler.changeAlarmState(CHANNEL_TAMPER_ALARM, OnOffType.OFF); } break; + case "Device/tnsaxis:HardwareFailure/StorageFailure": case "Device/HardwareFailure/StorageFailure": - if ("true".equals(dataValue)) { + if ("true".equals(dataValue) || "1".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.ON); - } else if ("false".equals(dataValue)) { + } else if ("false".equals(dataValue) || "0".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.OFF); } break; @@ -728,9 +742,9 @@ public class OnvifConnection { case "VideoSource/GlobalSceneChange/AnalyticsService": case "VideoSource/GlobalSceneChange/ImagingService": case "VideoSource/GlobalSceneChange/RecordingService": - if ("true".equals(dataValue)) { + if ("true".equals(dataValue) || "1".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.ON); - } else if ("false".equals(dataValue)) { + } else if ("false".equals(dataValue) || "0".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.OFF); } break;