keshavdv / unifi-cam-proxy

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

Proxy stuck at Hikvision PTZ discovery #373

Open MartynasZilinskas opened 1 month ago

MartynasZilinskas commented 1 month ago

Camera

Hikvision DS-7204HTHI-K2

Firmware version of the camera

V4.25.001 build 201107

Description

proxy-1-1  | 2024-06-01 22:41:44 50fd2ecc4d90 Core[1] INFO Creating ws connection to wss://{UNIFI}:7442/camera/1.0/ws?token={token}
proxy-1-1  | 2024-06-01 22:41:44 50fd2ecc4d90 HikvisionCam[1] INFO Adopting with token [{token}] and mac [AABBCCDDEEFF]
proxy-1-1  | 2024-06-01 22:41:44 50fd2ecc4d90 HikvisionCam[1] INFO Processing [ubnt_avclient_hello] message
proxy-1-1  | 2024-06-01 22:41:44 50fd2ecc4d90 HikvisionCam[1] INFO Detected PTZ support
proxy-1-1  | 2024-06-01 22:41:44 50fd2ecc4d90 HikvisionCam[1] INFO Connecting to motion events API
proxy-1-1  | 2024-06-01 22:41:45 50fd2ecc4d90 HikvisionCam[1] INFO Processing [ubnt_avclient_paramAgreement] message
proxy-1-1  | 2024-06-01 22:41:45 50fd2ecc4d90 HikvisionCam[1] INFO Processing [StopService] message
proxy-1-1  | 2024-06-01 22:41:45 50fd2ecc4d90 HikvisionCam[1] INFO Processing [ubnt_avclient_hello] message
proxy-1-1  | 2024-06-01 22:41:45 50fd2ecc4d90 HikvisionCam[1] INFO Processing [ChangeVideoSettings] message
proxy-1-1  | 2024-06-01 22:41:45 50fd2ecc4d90 HikvisionCam[1] INFO Processing [ChangeIspSettings] message
proxy-1-1  | 2024-06-01 22:41:45 50fd2ecc4d90 HikvisionCam[1] INFO Cleaning up instance
proxy-1-1  | Traceback (most recent call last):
proxy-1-1  |   File "/usr/local/bin/unifi-cam-proxy", line 8, in <module>
proxy-1-1  |     sys.exit(main())
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/main.py", line 119, in main
proxy-1-1  |     loop.run_until_complete(c.run())
proxy-1-1  |   File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
proxy-1-1  |     return future.result()
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/core.py", line 81, in run
proxy-1-1  |     await connect()
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/backoff/_async.py", line 66, in retry
proxy-1-1  |     ret = await target(*args, **kwargs)
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/core.py", line 72, in connect
proxy-1-1  |     await asyncio.gather(*tasks)
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/cams/base.py", line 78, in _run
proxy-1-1  |     force_reconnect = await self.process(msg)
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/cams/base.py", line 865, in process
proxy-1-1  |     res = await self.process_change_isp_settings(m)
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/cams/base.py", line 747, in process_change_isp_settings
proxy-1-1  |     payload.update(await self.get_video_settings())
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/unifi/cams/hikvision.py", line 70, in get_video_settings
proxy-1-1  |     r = (await self.cam.PTZCtrl.channels[1].status(method="get"))["PTZStatus"][
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/hikvisionapi/hikvisionapi.py", line 311, in common_request
proxy-1-1  |     response.raise_for_status()
proxy-1-1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 1510, in raise_for_status
proxy-1-1  |     raise HTTPStatusError(message, request=request, response=self)
proxy-1-1  | httpx.HTTPStatusError: Client error '403 Forbidden' for url 'http://{HIKVISION}/ISAPI/PTZCtrl/channels/1/status'
proxy-1-1  | For more information check: https://httpstatuses.com/403

Response of http://{HIKVISION}/ISAPI/PTZCtrl/channels/1/status endpoint:

<ResponseStatus xmlns="http://www.hikvision.com/ver20/XMLSchema" version="1.0">
<requestURL>/ISAPI/PTZCtrl/channels/1/status</requestURL>
<statusCode>4</statusCode>
<statusString>Invalid Operation</statusString>
<subStatusCode>invalidOperation</subStatusCode>
</ResponseStatus>

How to reproduce

Fails on initial start. User is an admin (has all permissions).

version: "3.5"
services:
  proxy-1:
    restart: unless-stopped
    build: ./unifi-cam-proxy
    volumes:
      - "./client.pem:/client.pem"
    command: >-
          unifi-cam-proxy
          -H {Unifi host}
          -i {Hikvision host}
          -c /client.pem
          -t {Unifi TOKEN}
          hikvision
          -u {user}
          -p {password}

Expected behaviour

Ignore PTZ controls if it's not possible.

Screenshots

No response

Additional information

No response

zacharee commented 2 weeks ago

What does http://{HIKVISION}/ISAPI/PTZCtrl/channels/1/capabilities return?

MartynasZilinskas commented 2 weeks ago

Thanks for looking into this.

I got the following response from this endpoint http://{HIKVISION}/ISAPI/PTZCtrl/channels/1/capabilities:

<?xml version="1.0" encoding="UTF-8" ?>
<PTZChannelCap version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<id min="1" max="12">1</id>
<enabled opt="true,false">false</enabled>
<videoInputID>1</videoInputID>
<controlProtocol opt="VIDO B-01,LG MULTIX,Samsung,SAE,YAAN-1,Tiandy,RedApple,PELCO-P,PELCO-D,TIANDY-PELCO-P,TIANDY-PELCO-D,1602-PROTOCOL,IntegrativeP,SONY-EVI-D30/31,SONY-EVI-D70,SONY-EVI-D100/P,TCL-PELCO-P,TCL-PELCO-D,TC-PELCO-P,TC-PELCO-D,Honeywell,Kony,YF-06,ADV,PIH-1016,YOULI,Infinovadcp001a,3609hd,A-01,AB-P,AB-D,ALSON,ANTEN,BBV-RS422,BEWATOR-PELCO-D,KC3360S,LILIN,RM110,ACES,DSCP,PLD,HY,NITRO,PELCO-RS422TY,PHILPS-3,VC-2000PTC-C,LC-D2104,TIANMIN-PELCO-P,TIANMIN-PELCO-D,Siemens,SPD-2200,DRAGON,TL-HHX2000,TL-PELCO-P,TL-V1200,VIDO B-02,NAIJIE,MAOWANG,SHINEI,YAAN-2,TECHWIN,PANASONIC_CS850,SUNELL,KTD-348,VICON,KALATEL,PHILIPS,INFINOVA,VCL,UTC,PELCO-C,AHD-C,Custom,HIKVISION-C,HIKVISION">UTC</controlProtocol>
<controlAddress>
<enabled opt="true">true</enabled>
<Address min="0" max="255">0</Address>
</controlAddress>
<PTZRs485Para>
<baudRate opt="2400,4800,9600,19200,38400,57600,115200">9600</baudRate>
<dataBits opt="5,6,7,8">8</dataBits>
<parityType opt="none,odd,even">none</parityType>
<stopBits opt="1,2">1</stopBits>
<flowCtrl opt="none,software,hardware">none</flowCtrl>
</PTZRs485Para>
<isSupportPosition3D>true</isSupportPosition3D>
</PTZChannelCap>
zacharee commented 2 weeks ago

Can you try my fork and see if it works? https://github.com/zacharee/unifi-cam-proxy