Setting up OctoPrint on a Raspberry Pi running Raspberry Pi OS (Debian)

Excellent guide. Just the right balance between too brief and too detailed!

2 Likes

To make the webcam work I had to add the script (with file name 'webcam') in directory /etc/init.d and not home/pi/scripts/webcam. Next, I did follow what was required for the webcamDaemon file (Make sure you create the file 'scripts'). Finally I executed the following two commands to make it work.

sudo chmod 755 /etc/init.d/webcam
sudo update-rc.d webcam defaults

Another note is you won't have to add the "/home/pi/scripts/webcam start" in the rc.local file.

Phenomenal post. Made an account just to <3 this!

1 Like

<If you want to be able to start and stop mjpeg-streamer from within OctoPrint, 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 :>

i Just want it to start when i startup the pi but it doesn't do shit

I guess you missed that part :wink:

@foosel thanks for a great tutorial. Please consider adding another Heads-up section somewhere next to camera optional section saying:
Don't forget to enable connection to the Raspberry Pi Camera in RPI config:

- sudo raspi-config
- choose '5 Interfacing Options/P1 Camera -> Enable'
- reboot

I configured lots of OctoPrints, but last time I spent quite some time looking for a reason why the camera didn't want to work :slight_smile:

1 Like

@foosel,

You may want to consider adding the following optionals to your guide:

1.Reduce priority of TouchUI/Webkit for the printer display: add

renice -n 19 -p $(pgrep WebKit)

to the end of startTouchUI.sh - once I did this my camera framerate became MUCH smoother
2. Set a static focal point for your webcam, if it can focus (like the C920):

v4l2-ctl --set-ctrl=focus_auto=0
v4l2-ctl --set-ctrl=focus_absolute=40 # your number here
1 Like

Honestly, the author of that plugin needs to own that suggestion, in my humble opinion. Why not create an issue on their repository and let them know what you experienced and suggest the workaround?

I donโ€™t think itโ€™s an issue with the plugin. Itโ€™s an issue with WebKit.

I just downloaded 0.17.0 from OctoPrint.org - Download & Setup OctoPrint. I installed on a Rapsberry Pi 4. Plugins did not work. I ssh'd into my pi and followed the guide from top to "pip install octoprint" and all works fine.

Hello @adamoutler!

So 0.17.0 is OctoPi - the complete solution for a Raspberry Pi. There is no need to install OctoPrint when this is installed.
This thread is about installing OctoPrint on an existing Raspian installation.
You may open a new thread with your issue.

Just letting people know that this helped with a reinstall on a stock octopi image. If you'd like to create such a thread, go ahead! I'm not really invested in this forum.

1 Like

Thanks for this guide! I scripted the major portions and made a few updates (current 2-2020). I also added some default profiles for Prusa printer models. I tried to be as thorough in the notes as possible, and anyone can add in their own printer profiles or modify the installer. The repo is here is anyone is interested: https://github.com/itcarsales/prusaPi

1 Like

Am I missing something here? I have no /home/pi/scripts/webcam directory.
If I make one with

#!/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

and 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

what type do I save those as? A .txt file?

For that matter, I have no scripts directory in the pi directory either. I feel like I am totally missing something here. All went well until that part. I am having a helluva time getting the Pi cam to work.
I flashed Octopi to a card and tried that way but just like this way I can only get the Pi Cam to work once. Soon as I reboot it never works again.
Great in-depth guide and I appreciate your work. Starting to think Pi Cam isn't the best way to do this. Thanks!

mkdir /home/pi/scripts
touch /home/pi/scripts/webcam
nano /home/pi/scripts/webcam
# -- Script contents begin, don't include this line
#!/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
# -- end script contents, don't include this line

touch /home/pi/scripts/webcamDaemon
nano /home/pi/scripts/webcamDaemon

# -- Script contents begin, don't include this line
#!/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
# -- end script contents, don't include this line

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

sudo nano /etc/rc.local # Add this before the final "exit 0" line.

# -- Script contents edit, don't include this line itself
/home/pi/scripts/webcam start
# -- end script edit, don't include this line
1 Like

Thanks so much! I appreciate you breaking it down for me. I'm a total noob and for some reason was getting lost. It makes much more sense to me reading it this way. Not to say the original post is lacking but I think I should have taken a break. At certain points my brain doesn't have any room left.

Edit: So far all is great! I shut down/rebooted multiple times and it's working great!
Just so someone else like me who may see this understands what I was doing wrong. I was not creating the file properly in the right directory and thus the editor, Nano, was asking for the file extension to save it correctly but couldn't since I started out wrong.

I was a software development instructor at some point and I know that the student doesn't necessarily know to "prepend sudo here" and such. (Many of the tutorials within this space assume that you are perhaps 50% proficient with Linux.)

I have Repetier Pi on mine and needed Octoprint running parallel. I am almost a total noob when it comes to Linux but know how to use Putty. Using this guide I was able to set up my Octoprint in no time with no issues, other than just looking up how to use nano to edit a file (also very simple). Thanks for the easy and clear instructions! :slight_smile:

For those of us who followed this guide...whats the official upgrade path to using python3.6+ for Octoprint 1.4.0 do we just reinstall it as pip3 (pip3.6 or pip3.7)

For now, it looks like this is the documentation for that. I'm sure there will be a blog post or similar soon enough here on the forum.

But you may want to wait (unless you're a plugin developer). Once you've changed over to Python 3 as the virtual environment, it will currently prevent about 80% of the plugins from running since they haven't yet been upgraded.

1 Like