Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ipcamera] Fix connection checks with ONVIF cameras with no snapshots #15119

Merged

Conversation

tb4jc
Copy link
Contributor

@tb4jc tb4jc commented Jun 19, 2023

This pull request is another try to fix the issue that connection check on ONVIF IP cams right now only work if snapshotPollling is active. Reported in issue 14910
Additionally, it gives the possibility to disable polling at startup.

@tb4jc tb4jc requested a review from Skinah as a code owner June 19, 2023 15:35
@tb4jc tb4jc force-pushed the 14910-fix-stop-poll-image-connection-handling branch from 64c0a7a to 91a01bc Compare June 19, 2023 15:55
@tb4jc tb4jc requested review from a team, cweitkamp and kaikreuzer as code owners June 19, 2023 15:55
…uests.

Also checking connect errors and setting new states connectError or refusedError accordingly.
On connect, only one request is sent to have less parallel actions in case of reconnect, timeout.
Moved GetCapabilities call to GetSystemDateAndTime response handler part.
Added support to disable automatic polling at startup.

Signed-off-by: Thomas Burri <th@thonojato.ch>
@tb4jc tb4jc force-pushed the 14910-fix-stop-poll-image-connection-handling branch from fba4072 to 37dac82 Compare June 20, 2023 06:33
@tb4jc tb4jc changed the title [ipcamera] Fixing connection check with ONVIF IP cams #14910 - next try [ipcamera] Fixing connection check with ONVIF IP cams - next try Jun 20, 2023
Comment on lines 535 to 537
} else {
logger.trace("cam not connected");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not like logging PLUS changing the THING STATUS as this is doubling up the info. Please remove as the cameraCommunicationError() line changes the thing status and this is the preferred way to let users know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense.


// if ONVIF cam also use connection state which is updated by regular messages to camera
if (thing.getThingTypeUID().getId().equals(ONVIF_THING) && snapshotUri.isEmpty()) {
logger.trace("is ONVIF with empty snapshot URI");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will create log entries way too often, if you want to log this is occuring, then consider placing a log comment on the first time the camera comes ONLINE and not every time the binding checks that the camera is still connected.

if (thing.getThingTypeUID().getId().equals(ONVIF_THING) && snapshotUri.isEmpty()) {
logger.trace("is ONVIF with empty snapshot URI");
if (onvifCamera.isConnected()) {
logger.trace("cam is connected");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, we do not need a log entry every time 'nothing is wrong'. There is a cost to performance if everything in your smart home started doing this, even if the logging level is not TRACE, there is a cost to check what the log level is.

// }
ctx.close();
} else {
logger.trace("other event received {}", evt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a little more descriptive like "Other ONVIF netty channel event occured {}" as Netty is also used for the main camera comms and a separate set for ONVIF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

} else if ((cause instanceof ConnectException)
&& cause.getMessage().contains("Connection refused")) {
logger.debug("Camera ONVIF port {} is refused.", onvifPort);
connectError = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be refusedError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Comment on lines 317 to 324
connecting.lock();
try {
connectError = false;
refusedError = false;
isConnected = true;
} finally {
connecting.unlock();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
connecting.lock();
try {
connectError = false;
refusedError = false;
isConnected = true;
} finally {
connecting.unlock();
}
setIsConnected(true);

Also need to add the following to the new setIsConnected(boolen) function:

connectError = false;
refusedError = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change both locations in the processReply() function to use the new function setIsConnected().
I reset connectError and refusedError also for case 'new connection state == false' as this leads to new reconnection attempts.

@Skinah
Copy link
Contributor

Skinah commented Jun 24, 2023

Thanks for the changes, have made all comments and the rest looks good. Just need to test these on my cameras to ensure its all good if the next build will be a STABLE build. Best this gets merged with some time to trial as a milestone as we must be getting close to the first 4.0 STABLE

@Skinah Skinah changed the title [ipcamera] Fixing connection check with ONVIF IP cams - next try [ipcamera] Fix connection checks with ONVIF cameras with no snapshots Jun 24, 2023
@Skinah Skinah added the bug An unexpected problem or unintended behavior of an add-on label Jun 24, 2023
Removed thing configuration 'disableSnapshotAtStartup' again.

Signed-off-by: Thomas Burri <th@thonojato.ch>
@lolodomo
Copy link
Contributor

@Skinah : did you approve this PR finally ?

@Skinah
Copy link
Contributor

Skinah commented Jul 16, 2023

@lolodomo LGTM

@lolodomo
Copy link
Contributor

There is now a conflict to resolve. Probably after I merged another PR.

Signed-off-by: Matthew Skinner <matt@pcmus.com>
@Skinah
Copy link
Contributor

Skinah commented Sep 10, 2023

@tb4jc I tried to fix the merge conflicts but it is now failing to build, can you look at it please so this can be merged? thanks

Signed-off-by: Thomas Burri <th@thonojato.ch>
…uilder).

Signed-off-by: Thomas Burri <th@thonojato.ch>
@tb4jc
Copy link
Contributor Author

tb4jc commented Sep 12, 2023

@Skinah: I fixed the conflicts

@tb4jc
Copy link
Contributor Author

tb4jc commented Sep 26, 2023

@Skinah Any update? Possible to merge now?

@Skinah
Copy link
Contributor

Skinah commented Sep 26, 2023

LGTM

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@lolodomo lolodomo merged commit fef9680 into openhab:main Sep 27, 2023
@lolodomo lolodomo added this to the 4.1 milestone Sep 27, 2023
Pshatsillo pushed a commit to Pshatsillo/openhab-addons that referenced this pull request Sep 29, 2023
…openhab#15119)

* Added connection check via IdleStateHandler events for sent onvif requests.
Also checking connect errors and setting new states connectError or refusedError accordingly.
On connect, only one request is sent to have less parallel actions in case of reconnect, timeout.
Moved GetCapabilities call to GetSystemDateAndTime response handler part.
Added support to disable automatic polling at startup.

* Fixed call of sendOnvifRequest (missed to remove one call of requestBuilder).

---------

Signed-off-by: Thomas Burri <th@thonojato.ch>
Signed-off-by: Matthew Skinner <matt@pcmus.com>
Co-authored-by: Matthew Skinner <matt@pcmus.com>
pat-git023 pushed a commit to pat-git023/openhab-addons that referenced this pull request Oct 13, 2023
…openhab#15119)

* Added connection check via IdleStateHandler events for sent onvif requests.
Also checking connect errors and setting new states connectError or refusedError accordingly.
On connect, only one request is sent to have less parallel actions in case of reconnect, timeout.
Moved GetCapabilities call to GetSystemDateAndTime response handler part.
Added support to disable automatic polling at startup.

* Fixed call of sendOnvifRequest (missed to remove one call of requestBuilder).

---------

Signed-off-by: Thomas Burri <th@thonojato.ch>
Signed-off-by: Matthew Skinner <matt@pcmus.com>
Co-authored-by: Matthew Skinner <matt@pcmus.com>
querdenker2k pushed a commit to querdenker2k/openhab-addons that referenced this pull request Oct 21, 2023
…openhab#15119)

* Added connection check via IdleStateHandler events for sent onvif requests.
Also checking connect errors and setting new states connectError or refusedError accordingly.
On connect, only one request is sent to have less parallel actions in case of reconnect, timeout.
Moved GetCapabilities call to GetSystemDateAndTime response handler part.
Added support to disable automatic polling at startup.

* Fixed call of sendOnvifRequest (missed to remove one call of requestBuilder).

---------

Signed-off-by: Thomas Burri <th@thonojato.ch>
Signed-off-by: Matthew Skinner <matt@pcmus.com>
Co-authored-by: Matthew Skinner <matt@pcmus.com>
querdenker2k pushed a commit to querdenker2k/openhab-addons that referenced this pull request Oct 29, 2023
…openhab#15119)

* Added connection check via IdleStateHandler events for sent onvif requests.
Also checking connect errors and setting new states connectError or refusedError accordingly.
On connect, only one request is sent to have less parallel actions in case of reconnect, timeout.
Moved GetCapabilities call to GetSystemDateAndTime response handler part.
Added support to disable automatic polling at startup.

* Fixed call of sendOnvifRequest (missed to remove one call of requestBuilder).

---------

Signed-off-by: Thomas Burri <th@thonojato.ch>
Signed-off-by: Matthew Skinner <matt@pcmus.com>
Co-authored-by: Matthew Skinner <matt@pcmus.com>
Signed-off-by: querdenker2k <querdenker2k@gmx.de>
austvik pushed a commit to austvik/openhab-addons that referenced this pull request Mar 27, 2024
…openhab#15119)

* Added connection check via IdleStateHandler events for sent onvif requests.
Also checking connect errors and setting new states connectError or refusedError accordingly.
On connect, only one request is sent to have less parallel actions in case of reconnect, timeout.
Moved GetCapabilities call to GetSystemDateAndTime response handler part.
Added support to disable automatic polling at startup.

* Fixed call of sendOnvifRequest (missed to remove one call of requestBuilder).

---------

Signed-off-by: Thomas Burri <th@thonojato.ch>
Signed-off-by: Matthew Skinner <matt@pcmus.com>
Co-authored-by: Matthew Skinner <matt@pcmus.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants