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);
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;
// 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);
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",
}
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",
"[{ \"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;
}
case ONVIF_THING:
return true;
case REOLINK_THING:
- if (cameraConfig.getNvrChannel() < 1) {
+ if (cameraConfig.getOnvifPort() > 0) {
return true;
}
}
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;
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);
}
}
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);
}
}
@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 = "";
+ mediaProfileTokens.get(mediaProfileIndex)
+ "</ProfileToken><Translation><Zoom x=\"-0.0240506344\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Translation></RelativeMove>";
case Renew:
- return "<Renew xmlns=\"http://docs.oasis-open.org/wsn/b-2\"><TerminationTime>PT1M</TerminationTime></Renew>";
+ return "<Renew xmlns=\"http://docs.oasis-open.org/wsn/b-2\"><TerminationTime>PT10S</TerminationTime></Renew>";
case GetConfigurations:
return "<GetConfigurations xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"></GetConfigurations>";
case GetConfigurationOptions:
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);
ipCameraHandler.rtspUri = rtspUri;
}
}
+ } else {
+ logger.trace("Unhandled ONVIF reply is: {}", message);
}
}
@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()));
}
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(
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");
}
}
}
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=\"");
default:
logger.debug("Please report this camera has an un-implemented ONVIF event. Topic: {}", topic);
}
- sendOnvifRequest(RequestType.Renew, subscriptionXAddr);
}
public boolean supportsPTZ() {