keshavdv / unifi-cam-proxy

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

UniFi Protect Application 1.19.0-beta.16 crashing #60

Closed robvde65 closed 3 years ago

robvde65 commented 3 years ago

UniFi Protect Application 1.19.0-beta.16 keeps crashing as soon as you start the proxy. Downgrade to 1.18.1 solved the issue.

Running with a TP-Link C100 and C110 and 4GB Raspberry Pi.

on another note: Running two containers on a single 4GB pi each servicing one camera (C100 and C110) results in some staggering feeds or not feed at all. Single 4GB PI with single container servicing one Pi works great. C100 is able to stream continuous, C110 streams with intervals of 5 sec

keshavdv commented 3 years ago

Fixed in version 0.1.4 on PyPI and the latest Docker image. Can you give that a go?

hamster commented 3 years ago

Tested as working for me with 1.19 and generic camera

tsspmq commented 3 years ago

Updated to the latest build with pip install --upgrade unifi-cam-proxy and used latest docker container and then updated NVR to 1.19.0 and it was crashing again just like with 1.03 of unifi-cam-proxy. Rolled the NVR back and started all the cameras back up and its working. Went to UDM-Pro started protect updated it to 1.19.0 for testing and it does same thing there (New token generated and used)

2021-08-22T14:06:49.190Z - error: unable to parse sd_notify status for unifi-protect: 2021-08-22T14:06:49.235Z - error: unable to parse http status for unifi-protect FetchError: request to http://127.0.0.1:7080/api/ucore/status failed, reason: connect ECONNREFUSED 127.0.0.1:7080 at ClientRequest. (/usr/share/unifi-core/app/webpack:/node_modules/node-fetch/lib/index.js:1461:11) at ClientRequest.emit (events.js:314:20) at Socket.socketErrorListener (_http_client.js:427:9) at Socket.emit (events.js:314:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21)

An rtsp stream, a frigate config and even the big buck bunny test do the same thing. I removed the image and made sure docker was at the latest as well, I run all my cameras via systemctl so its easy to use docker as a test without affecting the cameras.

Here is the command I'm using and protect immediately crashes and restarts, removed addresses and token:

docker run --rm -v "/root/cert.pem:/client.pem" keshavdv/unifi-cam-proxy unifi-cam-proxy --verbose --ip "xxxxxxxxxxxx" --host xxxxxxxxxxx --cert /client.pem --token xxxxxxxxxxx rtsp -s rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_175k.mo

2021-08-12T17:09:53.267Z - error: unhandledRejection, shutting down... 2021-08-12T17:09:53.270Z - error: TypeError: Cannot read property 'send' of null at e.exports.send (/usr/share/unifi-core/app/webpack:/node_modules/@ubnt/ucp4/src/index.js:98:29) at

keshavdv commented 3 years ago

@tsspmq Can you share log output from the unifi-cam-proxy command with the --verbose flag enabled and a larger chunk of the stacktrace you see in the unifi-protect logs from the NVR at the time of the crash?

tsspmq commented 3 years ago

Yeah, threw this on my unused pi, to the unused UDM-Pro at 1.19.0. Only difference between this and prod are the IP addresses and the token.

pi@raspberrypi1:~ $ sudo unifi-cam-proxy -H 192.168.1.1 -i 192.168.1.2 --mac 'AA:BB:CC:00:00:03' --verbose --cert /root/client.pem --token wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT frigate -s rtsp://192.168.1.3:8554/cam_3 --mqtt-host smartho
me --frigate-camera front_porch
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] INFO Spawning stream for snapshots: ffmpeg -nostdin -y -re -rtsp_transport tcp -i "rtsp://192.168.1.3:8554/cam_3" -vf fps=1 -update 1 /tmp/tmpavtvvzyj/screen.jpg
2021-08-22 13:01:48 raspberrypi1 Core[1143] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] INFO Adopting with token [wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT] and mac [AA:BB:CC:00:00:03]
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Sending: {'from': 'ubnt_avclient', 'functionName': 'ubnt_avclient_hello', 'inResponseTo': 0, 'messageId': 1, 'payload': {'adoptionCode': 'wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT', 'connectionHost': '192.168.1.1', 'connectionSecurePort': 7442, 'fwVersion': 'UVC.S2L.v4.23.8.67.0eba6e3.200526.1046', 'hwrev': 19, 'idleTime': 191.96, 'ip': '192.168.1.2', 'mac': 'AA:BB:CC:00:00:03', 'model': 'UVC G3', 'name': 'unifi-cam-proxy', 'protocolVersion': 67, 'rebootTimeoutSec': 30, 'semver': 'v4.4.8', 'totalLoad': 0.5474, 'upgradeTimeoutSec': 150, 'uptime': 0.12767577171325684, 'features': {'mic': True, 'smartDetect': ['person', 'vehicle']}}, 'responseExpected': False, 'to': 'UniFiVideo'}
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] INFO Connected to smarthome:1883
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG frigate/front_porch/+/snapshot
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] INFO Processing [ubnt_avclient_hello] message
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'functionName': 'ubnt_avclient_hello', 'messageId': 10000, 'inResponseTo': 1, 'payload': {'protocolVersion': 67, 'controllerName': 'Home UDM-Pro', 'controllerUuid': '0b7fef74-f388-474e-8ea0-ee14c206cea8', 'controllerVersion': '1.19.0', 'overrideUuid': True}}
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Discarding snapshot message (19597)
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Discarding snapshot message (18580)
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] INFO Processing [ubnt_avclient_hello] message
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'functionName': 'ubnt_avclient_hello', 'messageId': 10001, 'inResponseTo': 1, 'payload': {'protocolVersion': 67, 'controllerName': 'Home UDM-Pro', 'controllerUuid': '0b7fef74-f388-474e-8ea0-ee14c206cea8', 'controllerVersion': '1.19.0', 'overrideUuid': True}}
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Discarding snapshot message (14815)
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Discarding snapshot message (12512)
2021-08-22 13:01:48 raspberrypi1 FrigateCam[1143] DEBUG Discarding snapshot message (21595)
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] INFO Processing [ubnt_avclient_paramAgreement] message
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'responseExpected': True, 'functionName': 'ubnt_avclient_paramAgreement', 'messageId': 10002, 'inResponseTo': 0, 'payload': {'enableStatusCodes': True, 'useHeartbeats': False, 'heartbeatsTimeoutMs': 60000}}
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] DEBUG Sending: {'from': 'ubnt_avclient', 'functionName': 'ubnt_avclient_paramAgreement', 'inResponseTo': 10002, 'messageId': 2, 'payload': {'authToken': 'wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT', 'features': {'mic': True, 'smartDetect': ['person', 'vehicle']}}, 'responseExpected': False, 'to': 'UniFiVideo'}
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] INFO Processing [ubnt_avclient_paramAgreement] message
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'responseExpected': True, 'functionName': 'ubnt_avclient_paramAgreement', 'messageId': 10003, 'inResponseTo': 0, 'payload': {'enableStatusCodes': True, 'useHeartbeats': False, 'heartbeatsTimeoutMs': 60000}}
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] DEBUG Sending: {'from': 'ubnt_avclient', 'functionName': 'ubnt_avclient_paramAgreement', 'inResponseTo': 10003, 'messageId': 3, 'payload': {'authToken': 'wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT', 'features': {'mic': True, 'smartDetect': ['person', 'vehicle']}}, 'responseExpected': False, 'to': 'UniFiVideo'}
2021-08-22 13:01:49 raspberrypi1 FrigateCam[1143] INFO Cleaning up instance
2021-08-22 13:01:49 raspberrypi1 Core[1143] INFO Backing off connect(...) for 2.0s (True)
2021-08-22 13:01:51 raspberrypi1 Core[1143] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT
2021-08-22 13:01:51 raspberrypi1 Core[1143] INFO Backing off connect(...) for 4.0s (True)
2021-08-22 13:01:55 raspberrypi1 Core[1143] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT
2021-08-22 13:01:55 raspberrypi1 Core[1143] INFO Backing off connect(...) for 8.0s (True)
2021-08-22 13:02:03 raspberrypi1 Core[1143] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT
2021-08-22 13:02:03 raspberrypi1 Core[1143] INFO Backing off connect(...) for 10.0s (True)
^CTraceback (most recent call last):
  File "/usr/local/bin/unifi-cam-proxy", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/unifi/main.py", line 109, in main
    loop.run_until_complete(c.run())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever
    self._run_once()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 1739, in _run_once
    event_list = self._selector.select(timeout)
  File "/usr/lib/python3.7/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
tsspmq commented 3 years ago

by the way, I just end up aborting it, this will continue over and over until stopped, protect just keeps restarting. Once I saw it crash I stopped it (at the start of the traceback you can see the ^C)

tsspmq commented 3 years ago

This might help:

2021-08-22T17:02:09.957Z - error: Error: Camera FW is not compatible. Current: '', required: '>=4.22.13'. at openStream (/usr/share/unifi-protect/app/webpack:/src/middleware/video/evostream/streams.js:112:13) at getStreamAlias (/usr/share/unifi-protect/app/webpack:/src/middleware/video/evostream/streams.js:267:5) at getStreamAliasForLcm (/usr/share/unifi-protect/app/webpack:/src/middleware/video/evostream/streams.js:277:26) at n (/usr/share/unifi-protect/app/webpack:/src/middleware/video/evostream/streams.js:423:56) at Promise (/usr/share/unifi-protect/app/node_modules/handoff/handoff.js:31:37) at Promise.cancellationExecute [as _execute] (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/debuggability.js:406:9) at Promise._resolveFromExecutor (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/promise.js:518:18) at new Promise (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/promise.js:103:10) at next (/usr/share/unifi-protect/app/node_modules/handoff/handoff.js:29:14) at notifyObjects (/usr/share/unifi-protect/app/node_modules/handoff/handoff.js:63:12) at publishNotification (/usr/share/unifi-protect/app/node_modules/handoff/handoff.js:83:10) at publish (/usr/share/unifi-protect/app/node_modules/handoff/handoff.js:101:10) at Promise.map (/usr/share/unifi-protect/app/webpack:/src/middleware/ucore/index.js:64:26) at tryCatcher (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/util.js:16:23) at MappingPromiseArray._promiseFulfilled (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/map.js:68:38) at MappingPromiseArray.PromiseArray._iterate (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/promise_array.js:115:31) at MappingPromiseArray.init (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/promise_array.js:79:10) at MappingPromiseArray._asyncInit (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/map.js:37:10) at _drainQueueStep (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/async.js:97:12) at _drainQueue (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/async.js:86:9) at Async._drainQueues (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (/usr/share/unifi-protect/app/node_modules/bluebird/js/release/async.js:15:14) at runCallback (timers.js:810:20) at tryOnImmediate (timers.js:768:5) at processImmediate [as _immediateCallback] (timers.js:745:5)

keshavdv commented 3 years ago

Ah, it looks I missed the fix for the crash loop in the Frigate implementation. Can you share output when trying the RTSP test video?

tsspmq commented 3 years ago

Same output as the frigate (and same error in errors.log) pi@raspberrypi1:~ $ sudo unifi-cam-proxy -H 192.168.1.1 -i 192.168.1.2 --mac 'AA:BB:CC:00:00:03' --verbose --cert /root/client.pem --fw-version "4.22.13" --token wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT rtsp -s rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_175k.mov 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] INFO Spawning stream for snapshots: ffmpeg -nostdin -y -re -rtsp_transport tcp -i "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_175k.mov" -vf fps=1 -update 1 /tmp/tmppr9eve3v/screen.jpg 2021-08-22 13:16:18 raspberrypi1 Core[1273] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] INFO Adopting with token [wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT] and mac [AA:BB:CC:00:00:03] 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] DEBUG Sending: {'from': 'ubnt_avclient', 'functionName': 'ubnt_avclient_hello', 'inResponseTo': 0, 'messageId': 1, 'payload': {'adoptionCode': 'wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT', 'connectionHost': '192.168.1.1', 'connectionSecurePort': 7442, 'fwVersion': '4.22.13', 'hwrev': 19, 'idleTime': 191.96, 'ip': '192.168.1.2', 'mac': 'AA:BB:CC:00:00:03', 'model': 'UVC G3', 'name': 'unifi-cam-proxy', 'protocolVersion': 67, 'rebootTimeoutSec': 30, 'semver': 'v4.4.8', 'totalLoad': 0.5474, 'upgradeTimeoutSec': 150, 'uptime': 0.13637351989746094, 'features': {'mic': True}}, 'responseExpected': False, 'to': 'UniFiVideo'} 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] INFO Processing [ubnt_avclient_hello] message 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'functionName': 'ubnt_avclient_hello', 'messageId': 10000, 'inResponseTo': 1, 'payload': {'protocolVersion': 67, 'controllerName': 'Home UDM-Pro', 'controllerUuid': '0b7fef74-f388-474e-8ea0-ee14c206cea8', 'controllerVersion': '1.19.0', 'overrideUuid': True}} 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] INFO Processing [ubnt_avclient_hello] message 2021-08-22 13:16:18 raspberrypi1 RTSPCam[1273] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'functionName': 'ubnt_avclient_hello', 'messageId': 10001, 'inResponseTo': 1, 'payload': {'protocolVersion': 67, 'controllerName': 'Home UDM-Pro', 'controllerUuid': '0b7fef74-f388-474e-8ea0-ee14c206cea8', 'controllerVersion': '1.19.0', 'overrideUuid': True}} 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] INFO Processing [ubnt_avclient_paramAgreement] message 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'responseExpected': True, 'functionName': 'ubnt_avclient_paramAgreement', 'messageId': 10002, 'inResponseTo': 0, 'payload': {'enableStatusCodes': True, 'useHeartbeats': False, 'heartbeatsTimeoutMs': 60000}} 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] DEBUG Sending: {'from': 'ubnt_avclient', 'functionName': 'ubnt_avclient_paramAgreement', 'inResponseTo': 10002, 'messageId': 2, 'payload': {'authToken': 'wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT', 'features': {'mic': True}}, 'responseExpected': False, 'to': 'UniFiVideo'} 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] INFO Processing [ubnt_avclient_paramAgreement] message 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] DEBUG Message contents: {'from': 'UniFiVideo', 'to': 'ubnt_avclient', 'responseExpected': True, 'functionName': 'ubnt_avclient_paramAgreement', 'messageId': 10003, 'inResponseTo': 0, 'payload': {'enableStatusCodes': True, 'useHeartbeats': False, 'heartbeatsTimeoutMs': 60000}} 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] DEBUG Sending: {'from': 'ubnt_avclient', 'functionName': 'ubnt_avclient_paramAgreement', 'inResponseTo': 10003, 'messageId': 3, 'payload': {'authToken': 'wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT', 'features': {'mic': True}}, 'responseExpected': False, 'to': 'UniFiVideo'} 2021-08-22 13:16:19 raspberrypi1 RTSPCam[1273] INFO Cleaning up instance 2021-08-22 13:16:19 raspberrypi1 Core[1273] INFO Backing off connect(...) for 2.0s (True) 2021-08-22 13:16:21 raspberrypi1 Core[1273] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT 2021-08-22 13:16:21 raspberrypi1 Core[1273] INFO Backing off connect(...) for 4.0s (True) 2021-08-22 13:16:25 raspberrypi1 Core[1273] INFO Creating ws connection to wss://192.168.1.1:7442/camera/1.0/ws?token=wg7Lk6yaEpIiAF1Se1ZaKAMIY3Ofg6DT 2021-08-22 13:16:25 raspberrypi1 Core[1273] INFO Backing off connect(...) for 8.0s (True) ^CTraceback (most recent call last): File "/usr/local/bin/unifi-cam-proxy", line 10, in sys.exit(main()) File "/usr/local/lib/python3.7/dist-packages/unifi/main.py", line 109, in main loop.run_until_complete(c.run()) File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete self.run_forever() File "/usr/lib/python3.7/asyncio/base_events.py", line 539, in run_forever self._run_once() File "/usr/lib/python3.7/asyncio/base_events.py", line 1739, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.7/selectors.py", line 468, in select fd_event_list = self._selector.poll(timeout, max_ev)

keshavdv commented 3 years ago

From the output, that doesn't seem to be using the updated version. Can you please run unifi-cam-proxy --version to confirm that you're on 0.1.4?

tsspmq commented 3 years ago

pi@raspberrypi1:~ $ unifi-cam-proxy --version 0.1.4 pi@raspberrypi1:~ $

tsspmq commented 3 years ago

I ran a compare between the code downloaded manually and that in the dist packages and its the same. it looks like a few minor changes in cams/base.py and version.py are all that it pulled out of git.

keshavdv commented 3 years ago

I pushed a fix for the Frigate implementation. Once this build finishes, please try running the keshavdv/unifi-cam-proxy:dev image and confirm if that fixes things for you. Can you share the output of sudo unifi-cam-proxy --version? In the failing run, you use sudo which can change python paths but in the followup response, you don't.

tsspmq commented 3 years ago

GAH thats right, this testing pi I had installed it as pi and root a week back so it was in both places. On the production machine (an x86 rig) I didn't make that mistake. Sorry for wasting time on that one.

sudo pip3 install --upgrade unifi-cam-proxy upgraded it in /usr/local/lib..... and rtsp does work. I'll check out the frigate in that build you linked.

tsspmq commented 3 years ago

Works with frigate now. Good deal.