Webcam Only Works When SSH'd In

Camera model
Logitech Webcam C615

What is the problem?
I am using a Logitech Webcam C615 webcam for my Raspberry pi Octoprint setup. For some reason it no longer works unless I login via SSH, and enter the following commands. When I close the SSH session, the camera stops working.

What did you already try to solve it?

sudo systemctl restart webcamd
sudo systemctl enable webcamd

# Camera Settings, cron job usually sets these properly on startup, but it's hit or miss.
sudo v4l2-ctl --set-ctrl=focus_auto=0 && sudo v4l2-ctl --set-ctrl=focus_absolute=120

I also set these commands as buttons in the Octoprint UI via the config.yaml file to easily restart the camera and set parameters without SSH. Worked for a while when needed, and usually only the refocus command was ever necessary.

system:
    actions:
    -   action: refocuscamera
        command: sudo v4l2-ctl --set-ctrl=focus_auto=0 && sudo v4l2-ctl --set-ctrl=focus_absolute=120
        name: Refous Camera
    -   action: divider
    -   action: restartcamera
        command: sudo systemctl restart webcamd && sudo systemctl enable webcamd
        confirm: You are about to restart your webcam. This will break timelapse!
        name: Restart Camera

However it now stops working when I logout of ssh even after issuing those commands. To get it started I have to unplug and replug in the camera, login again and type the same commands again. I set my computer to keep the connection alive indefinitely, but that doesn't solve the core problem. I also set the user pi to no longer need 'sudo' in the 'sudoers' file. Thanks for any help you can give me!

Additional information about your setup (OctoPrint version, OctoPi version, ...)
browser.user_agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36
connectivity.connection_check: 8.8.8.8:53
connectivity.connection_ok: true
connectivity.enabled: true
connectivity.online: true
connectivity.resolution_check: octoprint.org
connectivity.resolution_ok: true
env.hardware.cores: 4
env.hardware.freq: 1500
env.hardware.ram: 3958259712
env.os.bits: 32
env.os.id: linux
env.os.platform: linux
env.plugins.pi_support.model: Raspberry Pi 4 Model B Rev 1.2
env.plugins.pi_support.octopi_version: 0.18.0
env.plugins.pi_support.throttle_state: 0x0
env.python.pip: 20.3.3
env.python.version: 3.7.3
env.python.virtualenv: true
octoprint.safe_mode: false
octoprint.version: 1.5.3
printer.firmware: Marlin 2.0.7.7C_NIC (Apr 18 2021

6 Likes