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

Camera crashes when going from "off" state to "on" state #23

Closed
kwirk opened this issue Apr 15, 2021 · 7 comments · Fixed by #26
Closed

Camera crashes when going from "off" state to "on" state #23

kwirk opened this issue Apr 15, 2021 · 7 comments · Fixed by #26

Comments

@kwirk
Copy link
Contributor

kwirk commented Apr 15, 2021

I had issues when camera goes from "off" to "on" state (via settings), causing camera to freeze. I found that numerous imggrabber processes were being created and hanging, caused by calls from Home Assistant trying to update the current snapshot.

I suspect issue is all those processes waiting for the next frame, and then them all trying at once to pull the frame when the camera is turned on again.

As a work around (or maybe an acceptable solution?), I've changed snapshot.sh to return error JSON when camera config is in off state:

diff --git a/src/www/httpd/cgi-bin/snapshot.sh b/src/www/httpd/cgi-bin/snapshot.sh
index d7499da..aff8b2c 100755
--- a/src/www/httpd/cgi-bin/snapshot.sh
+++ b/src/www/httpd/cgi-bin/snapshot.sh
@@ -10,6 +10,17 @@ validateFile()
     esac
 }
 
+YI_HACK_PREFIX="/tmp/sd/yi-hack-v5"
+CONF_FILE="$YI_HACK_PREFIX/etc/camera.conf"
+
+if grep -q SWITCH_ON=no "$CONF_FILE"; then
+    printf "Content-type: application/json\r\n\r\n"
+    printf "{\n"
+    printf "\"%s\":\"%s\"\\n" "error" "true"
+    printf "}"
+    exit 0
+fi
+
 MODEL_SUFFIX=$(cat /home/app/.camver)
 BASE64="no"
 RES="-r high"
@alienatedsec
Copy link
Owner

@kwirk Great suggestion, thanks.

A pull request will make it happen quicker :)

@alienatedsec
Copy link
Owner

@kwirk Thank you. I will merge when back at home.

@roleoroleo
Copy link
Collaborator

I will add a semaphore to run only one imggrabber session.

@kwirk
Copy link
Contributor Author

kwirk commented Apr 18, 2021

I will add a semaphore to run only one imggrabber session.

If you have multiple clients polling for snapshots that may not be ideal, limiting it to just one. But maybe a sensible limit would be better (which may depend on camera model).

@roleoroleo
Copy link
Collaborator

Another way: add a timeout using 2 threads.

@kwirk
Copy link
Contributor Author

kwirk commented Apr 18, 2021

Another way: add a timeout using 2 threads.

Yeah, I think it makes sense to have a timeout.

alienatedsec added a commit that referenced this issue Apr 19, 2021
[Fix] Snapshot return service unavailable when camera off
@roleoroleo
Copy link
Collaborator

I pushed a new commit.
d607881
Sorry but it's not tested, I don't have a compatible cam.

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

Successfully merging a pull request may close this issue.

3 participants