jschmid1 / gopro_as_webcam_on_linux

Allows to use your GoPro camera as a webcam on linux
Apache License 2.0
532 stars 67 forks source link

Using the auto start on plug it fails the first time, but succeeds the second time #17

Closed jgslade closed 3 years ago

jgslade commented 3 years ago

I've been able to get the udev rules to work to start and stop the service on plug. The only issue I have is thatit fails to discover a valid GOPRO_IP the first time, but when the the service restarts it finds it. Is there a way so it doesn't failthe first time?

First run

Apr 12 17:09:26 samticus-comouman systemd[1]: Started GoPro Webcam start script.
Apr 12 17:09:26 samticus-comouman gopro[165927]: Running GoPro Webcam Util for Linux [0.0.3]
Apr 12 17:09:26 samticus-comouman gopro[165927]:        Launch Options
Apr 12 17:09:26 samticus-comouman gopro[165927]: ==========================
Apr 12 17:09:26 samticus-comouman gopro[165927]:  * Non-interactive:  1
Apr 12 17:09:26 samticus-comouman gopro[165927]:  * Autostart:        1
Apr 12 17:09:26 samticus-comouman gopro[165927]:  * Preview:          0
Apr 12 17:09:26 samticus-comouman gopro[165927]:  * Device Pattern:   enp
Apr 12 17:09:26 samticus-comouman gopro[165927]: ==========================
Apr 12 17:09:26 samticus-comouman gopro[165927]: v4l2loopback is loaded!
Apr 12 17:09:26 samticus-comouman gopro[165927]: v4l2loopback was unloaded successfully.
Apr 12 17:09:26 samticus-comouman gopro[165927]: v4l2loopback was successfully loaded.
Apr 12 17:09:26 samticus-comouman gopro[165927]: Using provided device pattern enp
Apr 12 17:09:26 samticus-comouman gopro[165927]: 
Apr 12 17:09:26 samticus-comouman gopro[165927]: Discovered: enp1s0f0u4.
Apr 12 17:09:26 samticus-comouman gopro[165927]: Using enp1s0f0u4 to discover the GOPRO_IP.
Apr 12 17:09:26 samticus-comouman gopro[165927]: Could not automatically discover a valid GOPRO_IP. Use the '-p, -d or -i' option to provide more information. (see --help for more information)
Apr 12 17:09:26 samticus-comouman systemd[1]: gopro_webcam.service: Main process exited, code=exited, status=1/FAILURE
Apr 12 17:09:26 samticus-comouman systemd[1]: gopro_webcam.service: Failed with result 'exit-code'.
Apr 12 17:09:41 samticus-comouman systemd[1]: gopro_webcam.service: Scheduled restart job, restart counter is at 1.
Apr 12 17:09:41 samticus-comouman systemd[1]: Stopped GoPro Webcam start script.

Restart

Apr 12 17:09:41 samticus-comouman systemd[1]: Started GoPro Webcam start script.
Apr 12 17:09:41 samticus-comouman gopro[166016]: Running GoPro Webcam Util for Linux [0.0.3]
Apr 12 17:09:41 samticus-comouman gopro[166016]:        Launch Options
Apr 12 17:09:41 samticus-comouman gopro[166016]: ==========================
Apr 12 17:09:41 samticus-comouman gopro[166016]:  * Non-interactive:  1
Apr 12 17:09:41 samticus-comouman gopro[166016]:  * Autostart:        1
Apr 12 17:09:41 samticus-comouman gopro[166016]:  * Preview:          0
Apr 12 17:09:41 samticus-comouman gopro[166016]:  * Device Pattern:   enp
Apr 12 17:09:41 samticus-comouman gopro[166016]: ==========================
Apr 12 17:09:41 samticus-comouman gopro[166016]: v4l2loopback is loaded!
Apr 12 17:09:41 samticus-comouman gopro[166016]: v4l2loopback was unloaded successfully.
Apr 12 17:09:41 samticus-comouman gopro[166016]: v4l2loopback was successfully loaded.
Apr 12 17:09:41 samticus-comouman gopro[166016]: Using provided device pattern enp
Apr 12 17:09:41 samticus-comouman gopro[166016]: 
Apr 12 17:09:41 samticus-comouman gopro[166016]: Discovered: enp1s0f0u4.
Apr 12 17:09:41 samticus-comouman gopro[166016]: Using enp1s0f0u4 to discover the GOPRO_IP.
Apr 12 17:09:41 samticus-comouman gopro[166016]: Found 172.27.199.54
Apr 12 17:09:41 samticus-comouman gopro[166016]: To control the GoPro, we need to contact another interface (GOPRO_IP ending with .51).. Adapting internally..
Apr 12 17:09:41 samticus-comouman gopro[166016]: Now using this GOPRO_IP internally: 172.27.199.51

My modified 60-gopro.rules

SUBSYSTEM=="net", ATTRS{idVendor}=="2672", ATTRS{product}=="HERO9", ACTION=="add", RUN+="/usr/sbin/systemctl start gopro_webcam"
SUBSYSTEM=="net", ATTRS{idVendor}=="2672", ATTRS{product}=="HERO9", ACTION=="remove", RUN+="/usr/sbin/systemctl stop gopro_webcam"

My modified gopro_webcam.service

[Unit]
Description=GoPro Webcam start script
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
ExecStart=/usr/local/sbin/gopro webcam -p enp -a -n
Restart=on-failure
RestartSec=15s

[Install]
WantedBy=multi-user.target
NewoIsTaken commented 3 years ago

I think this is because the GoPro takes some time to initialize. Maybe if given the -n option you insert a delay before trying to find the IP? That may fix it.