JurajNyiri / HomeAssistant-Tapo-Control

Control for Tapo cameras as a Home Assistant component
Apache License 2.0
1.14k stars 89 forks source link

Bug: #65

Closed usma0118 closed 3 years ago

usma0118 commented 3 years ago

Describe the bug Camera becomes unresponsive after adding to HA via Tapo control

To Reproduce Steps to reproduce the behavior:

  1. Camera becomes unresponsive after adding to HA via Tapo Control
  2. Same issue with or without "stream from HA option"
  3. Camera no loner responds on rtsp stream.
  4. API's and response to ping still works fine.

Could you please link the issue you opened? it's support ticket with id: TKID210130188. comments from tplink support "It seems the issue is caused by the RTSP/Onvif."

Expected behavior stream accessible via HA

Log - Tapo C100 logs

[INFO][cet][RTSPClientSession]-1742: RTSPClientSession[0x721870] create RTSPClientSession
client requests unicast 192.100.1.120
client requests unicast 192.100.1.120
rangeStart:0.000000, rangeEnd:0.000000, duration:0.000000, scale:1.000000
startStream
RTSP start playing without create a new thread.
startStream
RTSP start playing without create a new thread.
[INFO][cet][handleRequestBytes]-1301: RTSPClientConnection[0x6fabb8] recv teardown. WaitingForFreeResource.
rtsp data thread starts to wait for main thread freeing resource.
[INFO][cet][handleRequestBytes]-1301: RTSPClientConnection[0x6fabb8] recv teardown. WaitingForFreeResource.
rtsp data thread starts to wait for main thread freeing resource.
deleteStream...
deleteStream...
[INFO][cet][~RTSPClientSession]-1747: RTSPClientSession[0x721870] delete RTSPClientSession
Delete rtsp connection 0x6fabb8.
rtsp data thread starts to wait for main thread freeing resource.
rtsp data thread starts to wait for main thread freeing resource.
[INFO][cet][~RTSPClientConnection]-645: RTSPClientConnection[0x6fabb8] delete RTSPClientConnection
[INFO][cet][~RTSPClientConnection]-668: RTSPClientConnection[0x6fabb8] RTSP:Remove connecting client. Current client num is 0
[INFO][cet][closeSockets]-1003: RTSPClientConnection[0x6fabb8] closeSockets... 23
####concurrent client num: 0, socket: 33
[INFO][cet][RTSPClientConnection]-633: RTSPClientConnection[0x707200] RTSP:Accept incoming client request. Current client num is 1
[INFO][cet][RTSPClientSession]-1742: RTSPClientSession[0x5ef2e0] create RTSPClientSession
client requests unicast 192.100.1.120
client requests unicast 192.100.1.120
rangeStart:0.000000, rangeEnd:0.000000, duration:0.000000, scale:1.000000
startStream
RTSP start playing without create a new thread.
startStream
RTSP start playing without create a new thread.
[INFO][cet][RTSPClientSession]-1742: RTSPClientSession[0x6b6350] create RTSPClientSession
[WARN][cet][check_and_add_preview_client_count]-148: Max main stream count is 2, current main stream is full
[INFO][cet][~RTSPClientSession]-1747: RTSPClientSession[0x6b6350] delete RTSPClientSession
Delete rtsp connection 0x707200.
rtsp data thread starts to wait for main thread freeing resource.
rtsp data thread starts to wait for main thread freeing resource.
[INFO][cet][~RTSPClientConnection]-645: RTSPClientConnection[0x707200] delete RTSPClientConnection
[INFO][cet][~RTSPClientConnection]-668: RTSPClientConnection[0x707200] RTSP:Remove connecting client. Current client num is 0
[INFO][cet][closeSockets]-1003: RTSPClientConnection[0x707200] closeSockets... 33
####concurrent client num: 0, socket: 23
[INFO][cet][RTSPClientConnection]-633: RTSPClientConnection[0x7218b0] RTSP:Accept incoming client request. Current client num is 1
[INFO][cet][RTSPClientSession]-1742: RTSPClientSession[0x6b78c0] create RTSPClientSession
[WARN][cet][check_and_add_preview_client_count]-148: Max main stream count is 2, current main stream is full
[INFO][cet][~RTSPClientSession]-1747: RTSPClientSession[0x6b78c0] delete RTSPClientSession
Delete rtsp connection 0x7218b0.
[INFO][cet][~RTSPClientConnection]-645: RTSPClientConnection[0x7218b0] delete RTSPClientConnection
[INFO][cet][~RTSPClientConnection]-668: RTSPClientConnection[0x7218b0] RTSP:Remove connecting client. Current client num is 0
[INFO][cet][closeSockets]-1003: RTSPClientConnection[0x7218b0] closeSockets... 23
####concurrent client num: 0, socket: 23
[INFO][cet][RTSPClientConnection]-633: RTSPClientConnection[0x707200] RTSP:Accept incoming client request. Current client num is 1
[INFO][cet][RTSPClientSession]-1742: RTSPClientSession[0x6b7308] create RTSPClientSession
[WARN][cet][check_and_add_preview_client_count]-148: Max main stream count is 2, current main stream is full
[INFO][cet][~RTSPClientSession]-1747: RTSPClientSession[0x6b7308] delete RTSPClientSession
Delete rtsp connection 0x707200.
[INFO][cet][~RTSPClientConnection]-645: RTSPClientConnection[0x707200] delete RTSPClientConnection
[INFO][cet][~RTSPClientConnection]-668: RTSPClientConnection[0x707200] RTSP:Remove connecting client. Current client num is 0
[INFO][cet][closeSockets]-1003: RTSPClientConnection[0x707200] closeSockets... 23
[WARN][cet][livenessTimeoutTask]-2603: RTSPClientSession[0x5fb130] RTSP session timeout... stream name "stream1".
rtsp data thread starts to wait for main thread freeing resource.
rtsp data thread starts to wait for main thread freeing resource.
[INFO][cet][~RTSPClientSession]-1747: RTSPClientSession[0x5fb130] delete RTSPClientSession
deleteStream...
deleteStream...
[ERROR][2021-01-21 18:28:59][vda] vda_ubus_call:963 - Failed to look up CET's ubus id
[ERROR][2021-01-21 18:28:59][vda] md_record_event_change:819 - Failed to call record's method "event change"
[ERROR][2021-01-21 18:29:14][vda] vda_ubus_call:963 - Failed to look up CET's ubus id
[ERROR][2021-01-21 18:29:14][vda] md_record_event_change:819 - Failed to call record's method "event change"
[ERROR][2021-01-21 18:29:35][vda] vda_ubus_call:963 - Failed to look up CET's ubus id
[ERROR][2021-01-21 18:29:35][vda] md_record_event_change:819 - Failed to call record's method "event change"
[default_wtd_func]-310: cet is missing, reboot the system...
Logger: homeassistant.setup
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/httpx/_exceptions.py", line 326, in map_exceptions
    yield
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1502, in _send_single_request
    (status_code, headers, stream, ext,) = await transport.arequest(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 218, in arequest
    response = await connection.arequest(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection.py", line 93, in arequest
    self.socket = await self._open_socket(timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection.py", line 119, in _open_socket
    return await self.backend.open_tcp_stream(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/auto.py", line 44, in open_tcp_stream
    return await self.backend.open_tcp_stream(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/asyncio.py", line 246, in open_tcp_stream
    return SocketStream(
  File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore.ConnectError: [Errno 111] Connect call failed ('192.100.1.148', 1024)

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

Traceback (most recent call last):
  File "/config/custom_components/tapo_control/__init__.py", line 147, in unsubscribe
    await hass.data[DOMAIN][entry.entry_id]["events"].async_stop()
  File "/usr/src/homeassistant/homeassistant/components/onvif/event.py", line 111, in async_stop
    await self._subscription.Unsubscribe()
  File "/usr/local/lib/python3.8/site-packages/zeep/proxy.py", line 64, in __call__
    return await self._proxy._binding.send_async(
  File "/usr/local/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 156, in send_async
    response = await client.transport.post_xml(
  File "/usr/local/lib/python3.8/site-packages/zeep/transports.py", line 230, in post_xml
    response = await self.post(address, message, headers)
  File "/usr/local/lib/python3.8/site-packages/zeep/transports.py", line 215, in post
    response = await self.client.post(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1633, in post
    return await self.request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1371, in request
    response = await self.send(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1406, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1444, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1476, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1502, in _send_single_request
    (status_code, headers, stream, ext,) = await transport.arequest(
  File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpx/_exceptions.py", line 343, in map_exceptions
    raise mapped_exc(message, **kwargs) from exc  # type: ignore
httpx.ConnectError: [Errno 111] Connect call failed ('192.100.1.148', 1024)

Camera (please complete the following information):

Using stream component yes

Camera works through onvif component OR different cameras work in general [yes/no]

Camera has all attributes filled out properly in developer tools yes

HASS Environment docker

Additional context Add any other context about the problem here.

JurajNyiri commented 3 years ago

This seems like the issue of camera, which corresponds with the response from tplink.

Does the rtsp stream work in vlc when this happens? Does onvif work via some other program when this happens?

Camera generally has issue when you inproperly end the connection with onvif, or when too many connections are opened to onvif, or rtsp. I think it supports about 2 or 3 streams via rtsp at the same time. Are you using more?

usma0118 commented 3 years ago

This seems like the issue of camera, which corresponds with the response from tplink. Yes, that's my hypothesis as well

Does the rtsp stream work in vlc when this happens? No Does onvif work via some other program when this happens? No

Camera generally has issue when you inproperly end the connection with onvif, or when too many connections are opened to onvif, or rtsp. I think it supports about 2 or 3 streams via rtsp at the same time. Are you using more? I am only using this via HA, which should open one stream only at a given time.

JurajNyiri commented 3 years ago

That points to a camera issue - if onvif and rtsp are unavailable you are either overloading it or there is some other bug.

This integration opens one onvif connection and two rtsp streams (one for HD and one for LQ). You can try disabling the entity for LQ and see if that improves anything.

Do RTSP and onvif work when you don't have camera added to Home Assistant?

usma0118 commented 3 years ago

That points to a camera issue - if onvif and rtsp are unavailable you are either overloading it or there is some other bug. seems to be a bug as I am not using any other system or app to access camera.

This integration opens one onvif connection and two rtsp streams (one for HD and one for LQ). You can try disabling the entity for LQ and see if that improves anything. Tried with no luck

Do RTSP and onvif work when you don't have camera added to Home Assistant? At least it shows better stability, but has problems

latest log:

2021-02-03 12:47:06 DEBUG (MainThread) [homeassistant.components.homekit.type_cameras] camera.tapo_camera_hd: Set linked motion binary_sensor.tapo_camera_motion sensor to 1

2021-02-03 12:47:06 DEBUG (MainThread) [homeassistant.components.homekit.type_cameras] camera.tapo_camera_sd: Set linked motion binary_sensor.tapo_camera_motion sensor to 1

2021-02-03 12:47:06 DEBUG (MainThread) [homeassistant.components.homekit.accessories] New_state: <state binary_sensor.tapo_camera_motion=on; friendly_name=Tapo_Camera - Motion, device_class=motion @ 2021-02-03T13:47:06.401683+01:00>

2021-02-03 12:47:06 DEBUG (MainThread) [homeassistant.components.homekit.type_sensors] binary_sensor.tapo_camera_motion: Set to 1

2021-02-03 12:47:11 DEBUG (MainThread) [homeassistant.components.homekit.type_cameras] camera.tapo_camera_hd: Set linked motion binary_sensor.tapo_camera_motion sensor to 0

2021-02-03 12:47:11 DEBUG (MainThread) [homeassistant.components.homekit.type_cameras] camera.tapo_camera_sd: Set linked motion binary_sensor.tapo_camera_motion sensor to 0

2021-02-03 12:47:11 DEBUG (MainThread) [homeassistant.components.homekit.accessories] New_state: <state binary_sensor.tapo_camera_motion=off; friendly_name=Tapo_Camera - Motion, device_class=motion @ 2021-02-03T13:47:11.577112+01:00>

2021-02-03 12:47:11 DEBUG (MainThread) [homeassistant.components.homekit.type_sensors] binary_sensor.tapo_camera_motion: Set to 0

2021-02-03 12:48:38 WARNING (MainThread) [homeassistant.helpers.entity] Update of camera.tapo_camera_hd is taking over 10 seconds

2021-02-03 12:48:58 WARNING (MainThread) [homeassistant.components.camera] Updating tapo_control camera took longer than the scheduled update interval 0:00:30

2021-02-03 12:52:25 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2021-02-03 12:52:34 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
usma0118 commented 3 years ago

Right now, i can view RTSP stream in tapo app. but above errors in HA.

JurajNyiri commented 3 years ago

Stream in tapo app works differently to rtsp stream. Try maybe removing the home kit from the equation, see if it helps.

JurajNyiri commented 3 years ago

Closing this as this is not related to this integration.