starkillerOG / reolink_aio

Reolink NVR/camera API PyPI package
MIT License
79 stars 16 forks source link

Unable to connect to Argus 3E #87

Closed ncul777 closed 3 weeks ago

ncul777 commented 3 weeks ago

Describe the bug I am unable to connect to an Argus 3E camera (which is bettery powered and uses baichuan protocol). I wasn't sure if the library supports this protocol but I did see a 'Baichuan' folder. The issue could well be a configuration / setup issue on my side, although I am able to ping the camera and capture an image from the camera using neolink.

See the error log at the very bottom

I was able to successfully connect to a Home Hub using reolink-aio

To Reproduce Use the example code from readme (with Host details changed) to connect to device

Expected behavior Expect connection to be made and the print statements to show host details.

Environment:

I had originally 0.10.1 but upgraded to 0.10.2

Collecting reolink-aio
  Downloading https://www.piwheels.org/simple/reolink-aio/reolink_aio-0.10.2-py3-none-any.whl (69 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 69.6/69.6 kB 1.4 MB/s eta 0:00:00
Requirement already satisfied: aiohttp in /usr/local/lib/python3.11/dist-packages (from reolink-aio) (3.10.10)
Requirement already satisfied: aiortsp in /usr/local/lib/python3.11/dist-packages (from reolink-aio) (1.4.0)
Requirement already satisfied: orjson in /usr/local/lib/python3.11/dist-packages (from reolink-aio) (3.10.10)
Requirement already satisfied: pycryptodomex in /usr/lib/python3/dist-packages (from reolink-aio) (3.11.0)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.11/dist-packages (from reolink-aio) (4.12.2)
Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->reolink-aio) (2.4.3)
Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp->reolink-aio) (1.3.1)
Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->reolink-aio) (24.2.0)
Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp->reolink-aio) (1.5.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp->reolink-aio) (6.1.0)
Requirement already satisfied: yarl<2.0,>=1.12.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->reolink-aio) (1.17.0)
Requirement already satisfied: dpkt~=1.9 in /usr/local/lib/python3.11/dist-packages (from aiortsp->reolink-aio) (1.9.8)
Requirement already satisfied: idna>=2.0 in /usr/lib/python3/dist-packages (from yarl<2.0,>=1.12.0->aiohttp->reolink-aio) (3.3)
Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from yarl<2.0,>=1.12.0->aiohttp->reolink-aio) (0.2.0)
Installing collected packages: reolink-aio
Successfully installed reolink-aio-0.10.2

Error log

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/baichuan/baichuan.py", line 116, in send
    self._transport, self._protocol = await self._loop.create_connection(
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('10.42.0.115', 9000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 1250, in _login_try_ports
    await self.baichuan.get_ports()
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/baichuan/baichuan.py", line 441, in get_ports
    mess = await self.send(cmd_id=37)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/baichuan/baichuan.py", line 83, in send
    await self.login()
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/baichuan/baichuan.py", line 382, in login
    nonce = await self._get_nonce()
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/baichuan/baichuan.py", line 268, in _get_nonce
    mess = await self.send(cmd_id=1, enc_type=EncType.BC, message_class="1465")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/baichuan/baichuan.py", line 122, in send
    raise ReolinkConnectionError(f"Baichuan host {self._host}: Connection error: {str(err)}") from err
reolink_aio.exceptions.ReolinkConnectionError: Baichuan host 10.42.0.115: Connection error: [Errno 111] Connect call failed ('10.42.0.115', 9000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/guardian/reolink.py", line 17, in <module>
    asyncio.run(print_mac_address())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/guardian/reolink.py", line 8, in print_mac_address
    await host.get_host_data()
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 2138, in get_host_data
    json_data = await self.send(body, expected_response_type="json")
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 5011, in send
    return await self.send_chunk(body, param, expected_response_type, retry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 5075, in send_chunk
    await self._login_open_port()
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 1340, in _login_open_port
    await self._login_try_ports()
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 1254, in _login_try_ports
    raise first_exc from exc
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 1234, in _login_try_ports
    await self.login()
  File "/usr/local/lib/python3.11/dist-packages/reolink_aio/api.py", line 1196, in login
    raise LoginError(f"Client connector error during login of host {self._host}:{self._port}: {str(err)}") from err
reolink_aio.exceptions.LoginError: Client connector error during login of host 10.42.0.115:443: Host 10.42.0.115:443: connection error: Cannot connect to host 10.42.0.115:443 ssl:default [Connect call failed ('10.42.0.115', 443)]
starkillerOG commented 3 weeks ago

The Baichuan implementation is very very new. I just made it in the past 2-3 weeks, so it is still rapidly developing.

That beeing sad, at this point the Baichuan protocol only implements a TCP connection. Reolink battery cameras don't support TCP connections, only UDP connections. You can use Reolink battery cameras with this libary (and the Home Assistant integration) using the Reolink Home Hub.

I am planning on supporting Baichuan UDP connections at some point, but I will probably not support Reolink Battery cameras in HomeAssistant withouth the Home Hub any time soon. This because even a UDP connection to the battery camera will likely keep it awake and theirfore rapidely drain its battery.

The Home Hub solves this issue by allowing the battery camera to go to sleep while HomeAssistant can keep a active TCP connection to the Home Hub.

ncul777 commented 3 weeks ago

No problem. As I mentioned on another issue I was able to connect and retrieve images from the Argus 3E via the Homehub.

I'd be happy to support if you need any testing done with or without homeassistant.