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

Retry onvif session #16544

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

toperichvania
Copy link

Proposed change

If camera is offline for any reason when frigate starts up first time, onvif session will not get established and PTZ will not work

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix/feature causing existing functionality to break)
  • [x ] Code quality improvements to existing code
  • Documentation Update

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • The code has been formatted using Ruff (ruff format frigate)

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for frigate-docs ready!

Name Link
🔨 Latest commit 23273ba
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/67ae000476c0f70008fa6820
😎 Deploy Preview https://deploy-preview-16544--frigate-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@NickM-27 NickM-27 left a comment

Choose a reason for hiding this comment

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

I don't think this is the right approach. Onvif has retry logic built in, and if that fails there is no indication that a camera will come back online soon. I can see it being better to wait until a user tries to interact with onvif then retry

@toperichvania
Copy link
Author

But that does not really happen ever. This happens only once on init (or in auto tracking):
`for cam_name, cam in config.cameras.items():
if not cam.enabled:
continue

        if cam.onvif.host:
            try:
                self.cams[cam_name] = {
                    "onvif": ONVIFCamera(
                        cam.onvif.host,
                        cam.onvif.port,
                        cam.onvif.user,
                        cam.onvif.password,
                        wsdl_dir=str(
                            Path(find_spec("onvif").origin).parent / "wsdl"
                        ),
                        adjust_time=cam.onvif.ignore_time_mismatch,
                        encrypt=not cam.onvif.tls_insecure,
                    ),
                    "init": False,
                    "active": False,
                    "features": [],
                    "presets": {},
                }
            except ONVIFError as e:
                logger.error(f"Onvif connection to {cam.name} failed: {e}")`

so self.cams will never get the offline camera in its list and any request like for example cam_name/ptz/info will return only empty dict as that camera is just not in self.cams.

Or I am missing on ways that user can interact with onvif of that camera once it is back online

@NickM-27
Copy link
Collaborator

so self.cams will never get the offline camera in its list and any request like for example cam_name/ptz/info will return only empty dict as that camera is just not in self.cams.

that's exactly the point, if a camera has onvif enabled then when a user (for example) opens the WebUI to that cameras view the webUI will call to get the cameras onvif capabilities. If the camera is not in self.cams but does have onvif defined then we know it failed to initialize and we can try to re-run that at that moment

@toperichvania
Copy link
Author

I seemed to have failed to find how this happens in a code :( (if not too much trouble, please point me in the direction where this call is happening). Of course I opened the Web UI and selected the camera but nothing really happened and when I made a API call to {cam}/ptz/info this always stayed empty dict {} so PTZ just never got to work unless I restarted frigate and then the ptz capabilities and presets were populated.

@NickM-27
Copy link
Collaborator

the retry part that I am referring to is me suggesting how this code should work. The webui part already exists, I am saying this PR should be adapted to try and reconnect in the case that I described above

@toperichvania
Copy link
Author

Aaaah ok.. I got you.. OK. that makes sense. I will amend my approach then.. Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants