keshavdv / unifi-cam-proxy

Enable non-Ubiquiti cameras to work with Unifi NVR
MIT License
1.72k stars 236 forks source link

Frigate cameras fall over when MQTT server is down. #71

Closed 5thsymphony closed 3 years ago

5thsymphony commented 3 years ago

I know obviously we need Frigate up and working to do the detections but when the Frigate or the MQTT server falls over is there anyway to avoid this package falling over too? I'd like to retain video support even whilst the detections support is down. Can you point me in the right direction? Happy to put in a pull request.

tsspmq commented 3 years ago

I solve the issue using systemd and restarting the service if it fails with reasonable delays and retry limits so it doesn't spin forever. I brought down the whole network, servers, everything today testing resilience of a complete power loss from DNS through VMs/Cameras/Proxy etc. The services actually started and connected to rtsp proxy. The only thing that I overlooked was the cameras powering up before dhcp was ready and they give up pretty quick and never try again. Static fixed that.

Example:

[Unit]
Description=Camera Proxy
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=5s

ExecStart=/usr/bin/python3 /usr/local/bin/unifi-cam-proxy -H <host> -i <camera> --mac <mac> --cert /srv/client.pem --model "UVC G4 Pro" --fw-version "4.41.16" --token <token> frigate -s rtsp://localhost:8554/cam_1a rtsp://localhost:8554/cam_1b rtsp://localhost:8554/cam_1c -i rtsp://localhost:8554/cam_1c --mqtt-host localhost --frigate-camera <frigate camera name>

[Install]
WantedBy=default.target
5thsymphony commented 3 years ago

Thanks for your response @tsspmq but my issue is regarding the fact that somewhere in the app we do something like:

This feels incorrect, it feels like we should:

The reason why is cameras trying to connect and disconnect several times in a minute can cause Protect to behave weirdly. It also makes sense to gracefully degrade to "no detections but feeds still working" if Frigate is down. We don't receive the feed directly from Frigate we receive it directly from the camera so we can do so.

keshavdv commented 3 years ago

Fixed in ede8de2aa6699cdc114a72d3e80a1bacb7c5bf24. Can you test it out and see if this works for you?

5thsymphony commented 3 years ago

I will test this and the HTTP basic auth stuff over the weekend. Thanks a lot for your efforts.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.