Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Configurable HTTP time out and throttle / stop connection attempts until ping succeeds #33

Closed
bagobones opened this issue Aug 8, 2021 · 5 comments

Comments

@bagobones
Copy link

The recent update seems to fix the offline state issue by using ping but I would like to suggest further stability improvements:

  1. The AD110 is VERY slow to respond to requests when booting or when it is constantly providing RTSP streams to an NVR, it looks like there is a hard coded 6.05s time out. I would suggest making this configurable to allow the user to adjust for their device.
    Trying again due to error: ReadTimeout(ReadTimeoutError("HTTPConnectionPool(host='192.168.103.8', port=80): Read timed out. (read timeout=6.05)"))
  2. While Ping seems to be used to figure out if the device is off the network, it doesn't stop repeated HTTP requests while the device is booting. I tested this with and without this docker running and the hammering while the device is booting seems to really slow it down. I would suggest that it should not attempt to sign in if ping hasn't succeeded at least 3-4 times.
    As an alternative the http connection also return if the Host is unreachable, this message could be used to back off connection attempts as it means that the device did not respond at all / is not online.
    Trying again due to error: ConnectionError(MaxRetryError("HTTPConnectionPool(host='192.168.103.8', port=80): Max retries exceeded with url: /cgi-bin/magicBox.cgi?action=getMachineName (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ADDRESS>: Failed to establish a new connection: [Errno 113] **Host is unreachable**'))"))

In my environment I have noted that there are at least 3 failed HTTP connections after a restart of this docker, I think backing off / increasing the time out or letting the user control it would help this work better.

@SharperThanThou
Copy link

While I haven't experience this exact issue, my container restarts due to a ping timeout dozens of times a day. I added more env variables to the py logic so I can easily tune the ping settings on the docker environment variables which are then consumed by the ping function:

ping_wait_ms = int(os.getenv("AMCREST_PINGWAIT") or 100)
ping_interval_sec = int(os.getenv("AMCREST_PINGINTERVAL") or 30)

def ping_camera():
Timer(ping_interval_sec, ping_camera).start()
response = os.system(f"ping -c1 -W{ping_wait_ms} {amcrest_host} >/dev/null 2>&1")

@cpettis
Copy link

cpettis commented Nov 21, 2021

This is the read error I see: Amcrest error HTTPConnectionPool(host='192.168.30.48', port=80): Read timed out.
The container restarts almost every hour due to this time out. I would think making the retries and timeout_cmd configurable would allow the user to fix this. As soon as the container restarts, it is able to read the configuration.
camera.event_actions("All", retries=5, timeout_cmd=(10.00, 3600))

@cpettis
Copy link

cpettis commented Nov 21, 2021

I should have left a more complete log.
21/11/2021 12:41:37 [INFO] Listening for events...
21/11/2021 13:41:37 [ERROR] Amcrest error HTTPConnectionPool(host='192.168.30.48', port=80): Read timed out.
21/11/2021 13:41:37 [INFO] Exiting app...
21/11/2021 13:41:40 [INFO] App Version: 1.0.11
21/11/2021 13:41:40 [INFO] Fetching camera details...
21/11/2021 13:41:44 [INFO] Device type: AD410
21/11/2021 13:41:44 [INFO] Serial number: Z173C93A7FAC1
21/11/2021 13:41:44 [INFO] Software version: 1.000.0000000.7.R
21/11/2021 13:41:44 [INFO] Device name: Front Door
21/11/2021 13:41:44 [INFO] Writing Home Assistant discovery config...
21/11/2021 13:41:44 [INFO] Fetching storage sensors...
21/11/2021 13:41:44 [INFO] Listening for events...
21/11/2021 14:41:44 [ERROR] Amcrest error HTTPConnectionPool(host='192.168.30.48', port=80): Read timed out.
21/11/2021 14:41:44 [INFO] Exiting app...
21/11/2021 14:41:47 [INFO] App Version: 1.0.11

This pattern repeats once an hour.

@rosiaantje
Copy link

To me it looks like #43 is refering to the same.. personally I have also some issues with the pinging of the device..

@hockeymikey
Copy link

I had this exact same issue with one of my doorbells (but not the other). It was because the one was streaming to an NVR and the other wasn't. Going into the python-amcrest config.py file and editing the timeout to a bigger number, I no longer saw the issue. This issue should be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants