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

Thank you for this! I actually forgot how venv's worked until I read that documentation. Totally went over my head that we can keep both versions running and switch as needed :smiley:

I have a Raspberry 3 and Octopi Rom with a pi cam, im not getting any image and from what it looks like the server isnt running right, it shows:
connect to 127.0.0.1 port 8080 failed: Connection refused
Failed to connect to localhost port 8080: Connection refused
when i type curl -v http://localhost:8080/

And when i follow the guide here i get stuck on ./mjpg_streamer -i "./input_raspicam.so -fps 5" -o "./output_http.so" where i get the return: -bash: ./mjpg_streamer: No such file or directory

What am i doing wrong?

Hello! After updating to the latest version (did it with the SD card image) I ran into the "purple haze problem" (https://www.raspberrypi.org/forums/viewtopic.php?t=245994) with my NoIR camera. The only solution should be to change the "AWB mode". But this is only possible if no other process is running which uses the camera. So I need to stop MJPG-streamer and tried to do it with this webcam scripts (webcam, webcamDaemon). I created those two files in the right location but... where I can now stop this process?? There is no further option now anywhere (or I can't find it). Or is there just a command to stop those process temporally via SSH? Tried it with "sudo killall mjpg_streamer" but this doesn't seem to stop the process. So would be so thankful for any help!

systemctl status webcamd.service

● webcamd.service - the OctoPi webcam daemon with the user specified config
   Loaded: loaded (/etc/systemd/system/webcamd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-03-11 10:07:52 PDT; 2h 45min ago
  Process: 344 ExecStart=/root/bin/webcamd (code=exited, status=0/SUCCESS)
 Main PID: 474 (mjpg_streamer)
    Tasks: 10 (limit: 4915)
   Memory: 4.4M
   CGroup: /system.slice/webcamd.service
           └─474 ./mjpg_streamer -o output_http.so -w ./www-octopi -n -i input_raspicam.so -fps 10

Mar 11 10:07:21 octopi mjpg_streamer[474]: MJPG-streamer [474]: username:password....: disabled
Mar 11 10:07:21 octopi mjpg_streamer[474]: MJPG-streamer [474]: commands.............: disabled
Mar 11 10:07:21 octopi mjpg_streamer[474]: MJPG-streamer [474]: starting input plugin input_raspicam.so
Mar 11 10:07:21 octopi mjpg_streamer[474]: MJPG-streamer [474]: starting output plugin: output_http.so (ID: 00)
Mar 11 10:07:21 octopi webcamd[344]:  i: Starting Camera
Mar 11 10:07:21 octopi mjpg_streamer[474]: MJPG-streamer [474]: Starting Camera
Mar 11 10:07:22 octopi webcamd[344]: Encoder Buffer Size 81920
Mar 11 10:07:52 octopi webcamd[344]: Done bring up all configured video device
Mar 11 10:07:52 octopi webcamd[344]: Goodbye...
Mar 11 10:07:52 octopi systemd[1]: Started the OctoPi webcam daemon with the user specified config.

sudo systemctl stop webcamd.service

WOW!!! You're the master! Thank you so much!!! This stopped the service indeed! Unfortunately it didn't solve my problem (purple haze) but this seems to be another story. Thank you anyway so much for your fast help!

1 Like

Here is a list of releases.

An update for how to run mjpg_streamer. Please bare in mind that I'm an amateur when it comes to Raspberry pi and linux/raspbian so this is going to be layman's terms at best.

New Raspbian stretches rely on shell scripts and to create the 2 scripts needed to run mjpg_streamer, you must simply create both the webcam and webcamDaemon scripts as webcam.sh and webcamDaemon.sh.

When creating webcam.sh, change the destination for the webcamDaemon from /home/pi/scripts/webcamDaemon to /home/pi/webcamDaemon.sh

The webcamDaemon code works as is (I'm using Logitech c270), you can adjust resolution etc. to your liking but remember to create it as webcamDaemon.sh

Make sure you chmod both scripts. To do so, simpy run chmod +x webcam.sh and chmod +x webcamDaemon.sh

Once the scripts are setup and executable, edit .octoprint/config.yaml system commands for streamon to /home/pi/webcam.sh start and streamoff to /home/pi/webcam.sh stop

I hope this helps because I spent hours going back and forth trying to figure out why my scripts weren't running.

Step by step:

sudo nano webcam.sh

Copy and paste below code

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

case "$1" in
    start)
        /home/pi/webcamDaemon.sh >/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

ctrl x to exit, y to save.

sudo nano webcamDaemon.sh

copy and paste bellow code

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

ctrl x to exit, y to save

then run bellow commands to make each script executable

chmod +x webcam.sh
chmod +x webcamDaemon.sh

then open up your octoprint yaml file

sudo nano .octoprint/config.yaml

and add to the bottom of the code

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

ctrl x to exit, y to save.

then restart OctoPrint sudo service octoprint restart and you should be able to start and stop your webcam via the UI.

Hi. Having issues with the webcam.
Im running this on an laptop running Debian.

The Snapshot is working, but the stream URL is not working. Any ideas?

Hey, I'm new here and followed that instruction, to install OctoPrint on my RaspberryPi. But now I have some problems starting the server... When I try to start the server this is what happens and I can't connect. Can someone explain whats wrong?

Thanks for your answers.

Anmerkung 2020-06-04 211746

looks ok for me
did you connect to http://raspberrypi:5000 ?

1 Like

Noo I connected to http://0.0.0.0:5000/ but now it's working. Thank you sooooo much. :smiley:

1 Like

I had the same problem. the /webcam/?action=stream is the path only if you setup using the instructions to get access via port80 (look at the sections under "Make everything accessible on port 80" in the original post). If you don't want to do that, then just put in: http://<your Raspi's IP>:8080/?action=stream

You can restrict parameter in sudoers like

pi ALL=NOPASSWD: /usr/sbin/service octoprint *

I'm working through this install but I have a question.

Under " Automatic start up", why is it having us use the init script instead of the systemd service file? Raspbian uses systemd now.

Or is it broken in some way?

Well they still work but yeah you're right - it might be time for a new startup file.
Any suggestions how it could look like?

It's actually just the wiki note that this guide is that needs some updating :wink:

Sure:

 wget https://raw.githubusercontent.com/OctoPrint/OctoPrint/master/scripts/octoprint.service && sudo mv octoprint.service /etc/systemd/system/
 wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default && sudo mv octoprint.default /etc/default/octoprint
sudo systemctl enable octoprint.service --now

That's what I did on mine.

1 Like

I'm having an issue with this section. I want to use a picam but this does not build the input_raspicam.so file that is needed. Any ideas what the problem is? I also opened an issue on the github page for this project.

EDIT: It was a problem with 64bit pi OS. The pi camera is not completely working yet on it.

Just a note, the webcamDaemon script will never use the "input_raspicam.so" for a pi camera with the default camera setting of "auto" (so auto really just means to use input_uvc.so for everything.). Because the if statement at the bottom looks for /dev/video0 first which the pi camera also uses.

I'm not sure if it is better or worse to use input_raspicam.so for a pi camera over input_uvc.so so maybe it doesn't matter.

EDIT: mjpeg_streamer uses a lot less CPU when using input_uvc.so vs more CPU when using input_raspicam.so so I guess it is fine how it is.

Here is a very simple systemd service file to use instead of adding the webcam stuff to the rc.local, which is messy. It uses the scripts above as well, because why not:

/etc/systemd/system/mjpg-streamer.service

[Unit]
Description=mjgp-streamer webcam streaming daemon
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
User=pi
ExecStart=/home/pi/scripts/webcam start
ExecStop=/home/pi/scripts/webcam stop

[Install]
WantedBy=multi-user.target

Hello everyone
I do not know English,These texts are all translated by Google,Hope you can understand
The problem I have is Raspberry 4B Webcam Do not show and After a while ssh connection error

OctoPi no problem

大家好
我不会英文,这些文字都是谷歌翻译得到的
我遇到的问题是Raspberry4B 摄像头不显示 一段时间后ssh连接中断显示Access denied(不确定是什么的问题)
OctoPi没有问题,显示连接都是可以的

MJPG Streamer Version: git rev: 85f89a8c321e799fabb1693c5d133f3fb48ee748
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: -1
i: Format............: JPEG
i: TV-Norm...........: DEFAULT
i: Could not obtain the requested pixelformat: MJPG , driver gave us: YUYV
[...]
o: www-folder-path......: disabled
o: HTTP TCP port........: 8080
o: HTTP Listen Address..: (null)
o: username:password....: disabled
o: commands.............: enabled