USB Camera Issues with Manual Octopi install

I am running Octoprint manually on my Rpi4 which also runs Pihole/PiVPN. Since this isn't an image, I had to configure the webcam differently and did not work out of the box. I run the following script to manually start the camera in terminal

cd mjpg-streamer/mjpg-streamer-experimental  
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so"

This turns on the camera and it works fine but the focus is off and I was trying to turn off the autofocus based on a guide (linked below). however, when I run the code I do not get the camera's focus to change.

sudo v4l2-ctl --set-ctrl=focus_auto=0
unknown control 'focus_auto'

Focus Issue - Screenshot by Lightshot

Camera model
Logitech c270

What is the problem?
I have a few errors when I try to turn off auto exposure as seen in these instructions: [Octoprint] Configure an USB webcam - Myzhar's MyzharBot and more...

What did you already try to solve it?
sudo uvcdynctrl -s 'Exposure, Auto' 1
sudo uvcdynctrl -s 'White Balance Temperature, Auto' 0
sudo v4l2-ctl --set-ctrl=focus_auto=0



**Additional information about your setup** (OctoPrint version, OctoPi version, ...)
* <small>OctoPrint 1.5.3</small>
* <small>Python 3.7.3</small>
RPi4[octoprint.log|attachment](upload://7pizSsg5eZaP8ms2FC5EkySYnRN.log) (126.3 KB) 


Logs attached. I see errors but not sure what they mean.[octoprint.log|attachment](upload://7pizSsg5eZaP8ms2FC5EkySYnRN.log) (126.3 KB)

run v4l2-ctl -l to get a list of all available parameters (or v4l2-ctl -L for a list with expanded menus)

Oddly enough there is no focus parameter. I guess that was why it didn't work. On a related item how do I make this run without me having to manually write the code?

cd mjpg-streamer/mjpg-streamer-experimental
pi@raspberrypi:~/mjpg-streamer/mjpg-streamer-experimental $ ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so"

you could add it to the /etc/rc.local file (add it above the line that reads exit 0).


But may I suggest something a bit more advanced?

put the following in /home/pi/scripts/webcam:

#!/bin/bash
# Start / stop streamer daemon

case "$1" in
    start)
        /home/pi/scripts/webcamDaemon >/dev/null 2>&1 &
        echo "$0: started"
        ;;
    stop)
        pkill -x webcamDaemon
        pkill -x mjpg_streamer
        echo "$0: stopped"
        ;;
    *)
        echo "Usage: $0 {start|stop}" >&2
        ;;
esac

Put this in /home/pi/scripts/webcamDaemon:

#!/bin/bash

MJPGSTREAMER_HOME=/home/pi/mjpg-streamer/mjpg-streamer-experimental
MJPGSTREAMER_INPUT_USB="input_uvc.so"
MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"

# init configuration
camera="auto"
camera_usb_options="-r 640x480 -f 10"
camera_raspi_options="-fps 10"

if [ -e "/boot/octopi.txt" ]; then
    source "/boot/octopi.txt"
fi

# runs MJPG Streamer, using the provided input plugin + configuration
function runMjpgStreamer {
    input=$1
    pushd $MJPGSTREAMER_HOME
    echo Running ./mjpg_streamer -o "output_http.so -w ./www" -i "$input"
    LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w ./www" -i "$input"
    popd
}

# starts up the RasPiCam
function startRaspi {
    logger "Starting Raspberry Pi camera"
    runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
}

# starts up the USB webcam
function startUsb {
    logger "Starting USB webcam"
    runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options"
}

# we need this to prevent the later calls to vcgencmd from blocking
# I have no idea why, but that's how it is...
vcgencmd version

# echo configuration
echo camera: $camera
echo usb options: $camera_usb_options
echo raspi options: $camera_raspi_options

# keep mjpg streamer running if some camera is attached
while true; do
    if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then
        startUsb
    elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then
        startRaspi
    fi

    sleep 120
done

Make sure both files are executable:

chmod +x /home/pi/scripts/webcam
chmod +x /home/pi/scripts/webcamDaemon

If you want different camera options put them in /boot/octopi.txt or modify the script accordingly.

If you want autostart of the webcam you need to add the following line to /etc/rc.local (Just make sure to put it above the line that reads exit 0).

/home/pi/scripts/webcam start

If you want to be able to start and stop the webcam server through OctoPrint's system menu, add the following to config.yaml:

system:
  actions:
   - action: streamon
     command: /home/pi/scripts/webcam start
     confirm: false
     name: Start video stream
   - action: streamoff
     command: sudo /home/pi/scripts/webcam stop
     confirm: false
     name: Stop video stream

source

of course you can change the paths and parameters to anything you want

Funny I had all that except for:

If you want autostart of the webcam you need to add the following line to /etc/rc.local (Just make sure to put it above the line that reads exit 0 ).

/home/pi/scripts/webcam start

However after reboot I still the error in the control screen - Screenshot by Lightshot

Also when I start the camera from Octopi I have this error - Screenshot by Lightshot

You might be using the wrong url

Does http://IP-OF-THE-PI:8080/?action=stream show you a picture?

Only when I envoke pi@raspberrypi:~/mjpg-streamer/mjpg-streamer-experimental

The url has worked with the above manually but using all the code you posted and restarting the pi doesn't work.