diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java
index 4e49c4116b7..7216b486c53 100644
--- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java
+++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java
@@ -178,11 +178,11 @@ public class HikvisionHandler extends ChannelDuplexHandler {
removeChannels.add(channel);
}
// start checking the input IO status
- ipCameraHandler.lowPriorityRequests.set(0,
+ ipCameraHandler.lowPriorityRequests.add(0,
"/ISAPI/System/IO/inputs/" + ipCameraHandler.cameraConfig.getNvrChannel() + "/status");
} else {
// start checking the input IO status
- ipCameraHandler.lowPriorityRequests.set(0,
+ ipCameraHandler.lowPriorityRequests.add(0,
"/ISAPI/System/IO/inputs/" + ipCameraHandler.cameraConfig.getNvrChannel() + "/status");
}
ipCameraHandler.removeChannels(removeChannels);
diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java
index 6a6650de9d5..0004c569572 100644
--- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java
+++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java
@@ -61,6 +61,7 @@ import org.openhab.binding.ipcamera.internal.IpCameraDynamicStateDescriptionProv
import org.openhab.binding.ipcamera.internal.MyNettyAuthHandler;
import org.openhab.binding.ipcamera.internal.ReolinkHandler;
import org.openhab.binding.ipcamera.internal.onvif.OnvifConnection;
+import org.openhab.binding.ipcamera.internal.onvif.OnvifConnection.RequestType;
import org.openhab.binding.ipcamera.internal.servlet.CameraServlet;
import org.openhab.core.OpenHAB;
import org.openhab.core.library.types.DecimalType;
@@ -1556,19 +1557,13 @@ public class IpCameraHandler extends BaseThingHandler {
// what needs to be done every poll//
switch (thing.getThingTypeUID().getId()) {
case GENERIC_THING:
- if (!snapshotPolling) {
- checkCameraConnection();
- }
+ checkCameraConnection();
break;
case ONVIF_THING:
- if (!snapshotPolling) {
- checkCameraConnection();
- }
+ onvifCamera.sendOnvifRequest(RequestType.Renew, onvifCamera.subscriptionXAddr);
break;
case INSTAR_THING:
- if (!snapshotPolling) {
- checkCameraConnection();
- }
+ checkCameraConnection();
noMotionDetected(CHANNEL_MOTION_ALARM);
noMotionDetected(CHANNEL_PIR_ALARM);
noMotionDetected(CHANNEL_HUMAN_ALARM);
@@ -1588,19 +1583,14 @@ public class IpCameraHandler extends BaseThingHandler {
sendHttpGET("/cgi-bin/eventManager.cgi?action=getEventIndexes&code=AudioMutation");
break;
case REOLINK_THING:
- if (cameraConfig.getNvrChannel() > 0) {
- sendHttpGET("/api.cgi?cmd=GetAiState&channel=" + cameraConfig.getNvrChannel() + "&user="
- + cameraConfig.getUser() + "&password=" + cameraConfig.getPassword());
- sendHttpGET("/api.cgi?cmd=GetMdState&channel=" + cameraConfig.getNvrChannel() + "&user="
- + cameraConfig.getUser() + "&password=" + cameraConfig.getPassword());
- } else if (!snapshotPolling) {
- checkCameraConnection();
+ if (cameraConfig.getOnvifPort() == 0) {
+ sendHttpGET("/api.cgi?cmd=GetAiState&channel=" + cameraConfig.getNvrChannel() + reolinkAuth);
+ sendHttpGET("/api.cgi?cmd=GetMdState&channel=" + cameraConfig.getNvrChannel() + reolinkAuth);
+ } else {
+ onvifCamera.sendOnvifRequest(RequestType.Renew, onvifCamera.subscriptionXAddr);
}
break;
case DAHUA_THING:
- if (!snapshotPolling) {
- checkCameraConnection();
- }
// Check for alarms, channel for NVRs appears not to work at filtering.
if (streamIsStopped("/cgi-bin/eventManager.cgi?action=attach&codes=[All]")) {
logger.info("The alarm stream was not running for camera {}, re-starting it now",
@@ -1609,9 +1599,6 @@ public class IpCameraHandler extends BaseThingHandler {
}
break;
case DOORBIRD_THING:
- if (!snapshotPolling) {
- checkCameraConnection();
- }
// Check for alarms, channel for NVRs appears not to work at filtering.
if (streamIsStopped("/bha-api/monitor.cgi?ring=doorbell,motionsensor")) {
logger.info("The alarm stream was not running for camera {}, re-starting it now",
@@ -1733,20 +1720,14 @@ public class IpCameraHandler extends BaseThingHandler {
"[{ \"cmd\":\"GetAbility\", \"param\":{ \"User\":{ \"userName\":\"admin\" }}}]");
}
if (snapshotUri.isEmpty()) {
- if (cameraConfig.getNvrChannel() < 1) {
- snapshotUri = "/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=openHAB" + reolinkAuth;
- } else {
- snapshotUri = "/cgi-bin/api.cgi?cmd=Snap&channel=" + (cameraConfig.getNvrChannel() - 1)
- + "&rs=openHAB" + reolinkAuth;
- }
+ // ReolinkHandler will change the snapshotUri in the response to /api.cgi?cmd=Login
+ snapshotUri = "/cgi-bin/api.cgi?cmd=Snap&channel=" + cameraConfig.getNvrChannel() + "&rs=openHAB"
+ + reolinkAuth;
}
+ // channel numbers for snapshots start at 0, while the rtsp start at 1
if (rtspUri.isEmpty()) {
- if (cameraConfig.getNvrChannel() < 1) {
- rtspUri = "rtsp://" + cameraConfig.getIp() + ":554/h264Preview_01_main";
- } else {
- rtspUri = "rtsp://" + cameraConfig.getIp() + ":554/h264Preview_0" + cameraConfig.getNvrChannel()
- + "_main";
- }
+ rtspUri = "rtsp://" + cameraConfig.getIp() + ":554/h264Preview_0"
+ + (cameraConfig.getNvrChannel() + 1) + "_main";
}
break;
}
@@ -1777,7 +1758,7 @@ public class IpCameraHandler extends BaseThingHandler {
case ONVIF_THING:
return true;
case REOLINK_THING:
- if (cameraConfig.getNvrChannel() < 1) {
+ if (cameraConfig.getOnvifPort() > 0) {
return true;
}
}
diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifCodec.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifCodec.java
index 091213c95ae..7c54ad978d1 100644
--- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifCodec.java
+++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifCodec.java
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpContent;
+import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.CharsetUtil;
@@ -46,6 +47,11 @@ public class OnvifCodec extends ChannelDuplexHandler {
return;
}
try {
+ if (msg instanceof HttpResponse response) {
+ if (response.status().code() != 200) {
+ logger.trace("ONVIF replied with code {} message is {}", response.status().code(), msg);
+ }
+ }
if (msg instanceof HttpContent content) {
incomingMessage += content.content().toString(CharsetUtil.UTF_8);
}
@@ -65,11 +71,11 @@ public class OnvifCodec extends ChannelDuplexHandler {
}
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
- logger.trace("IdleStateEvent received: {}", e.state());
+ logger.debug("IdleStateEvent received: {}", e.state());
onvifConnection.setIsConnected(false);
ctx.close();
} else {
- logger.trace("Other ONVIF netty channel event occurred: {}", evt);
+ logger.debug("ONVIF netty channel event occurred: {}", evt);
}
}
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 e6cd9d10d8b..d65e2802978 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
@@ -128,7 +128,7 @@ public class OnvifConnection {
@SuppressWarnings("unused")
private String imagingXAddr = "http://" + ipAddress + "/onvif/device_service";
private String ptzXAddr = "http://" + ipAddress + "/onvif/ptz_service";
- private String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service";
+ public String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service";
private boolean isConnected = false;
private int mediaProfileIndex = 0;
private String rtspUri = "";
@@ -269,7 +269,7 @@ public class OnvifConnection {
+ mediaProfileTokens.get(mediaProfileIndex)
+ "";
case Renew:
- return "PT1M";
+ return "PT10S";
case GetConfigurations:
return "";
case GetConfigurationOptions:
@@ -310,8 +310,8 @@ public class OnvifConnection {
logger.trace("ONVIF reply is: {}", message);
if (message.contains("PullMessagesResponse")) {
eventRecieved(message);
- } else if (message.contains("RenewResponse")) {
sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
+ } else if (message.contains("RenewResponse")) {
} else if (message.contains("GetSystemDateAndTimeResponse")) {// 1st to be sent.
setIsConnected(true);// Instar profile T only cameras need this
parseDateAndTime(message);
@@ -380,6 +380,8 @@ public class OnvifConnection {
ipCameraHandler.rtspUri = rtspUri;
}
}
+ } else {
+ logger.trace("Unhandled ONVIF reply is: {}", message);
}
}
@@ -568,7 +570,7 @@ public class OnvifConnection {
@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
- socketChannel.pipeline().addLast("idleStateHandler", new IdleStateHandler(20, 20, 20));
+ socketChannel.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 18));
socketChannel.pipeline().addLast("HttpClientCodec", new HttpClientCodec());
socketChannel.pipeline().addLast("OnvifCodec", new OnvifCodec(getHandle()));
}
@@ -583,14 +585,14 @@ public class OnvifConnection {
if (future == null) {
return;
}
- if (future.isSuccess()) {
+ if (future.isDone() && future.isSuccess()) {
Channel ch = future.channel();
ch.writeAndFlush(request);
} else { // an error occurred
if (future.isDone() && !future.isCancelled()) {
Throwable cause = future.cause();
String msg = cause.getMessage();
- logger.debug("connect failed - cause {}", cause.getMessage());
+ logger.debug("Connect failed - cause is: {}", cause.getMessage());
if (cause instanceof ConnectTimeoutException) {
usingEvents = false;// Prevent Unsubscribe from being sent
ipCameraHandler.cameraCommunicationError(
@@ -601,9 +603,8 @@ public class OnvifConnection {
ipCameraHandler.cameraCommunicationError(
"Camera refused to connect when using ONVIF to port:" + port);
}
- }
- if (isConnected) {
- disconnect();
+ } else {
+ ipCameraHandler.cameraCommunicationError("Camera failed to connect due to being cancelled");
}
}
}
@@ -652,7 +653,7 @@ public class OnvifConnection {
public void eventRecieved(String eventMessage) {
String topic = Helper.fetchXML(eventMessage, "Topic", "tns1:");
if (topic.isEmpty()) {
- sendOnvifRequest(RequestType.Renew, subscriptionXAddr);
+ logger.debug("No ONVIF Events occured in the last 8 seconds");
return;
}
String dataName = Helper.fetchXML(eventMessage, "tt:Data", "Name=\"");
@@ -782,7 +783,6 @@ public class OnvifConnection {
default:
logger.debug("Please report this camera has an un-implemented ONVIF event. Topic: {}", topic);
}
- sendOnvifRequest(RequestType.Renew, subscriptionXAddr);
}
public boolean supportsPTZ() {