Octo Print for controlling and monitoring 3D printing from Raspberry PI

Octo Print for controlling and monitoring 3D printing from Raspberry PI

Installing Octo Print on Raspberry Pi 3

  1. Install a Clean Raspbian Lite
  2. apt-get update
  3. apt-get install python-pip python-dev python-setuptools python-virtualenv git libyaml-dev build-essential
  4. cd OctoPrint
  5. virtualenv venv
  6. ./venv/bin/pip install pip –upgrade
  7. ./venv/bin/python setup.py install
  8. mkdir ~/.octoprint
  9. sudo usermod -a -G tty pi
  10. sudo usermod -a -G dialout pi
  11. ~/OctoPrint/venv/bin/octoprint serve

Installing Camera Support on Raspberry Pi 3

  1. apt-get install subversion libjpeg62-turbo-dev imagemagick ffmpeg libv4l-dev cmake
  2. git clone https://github.com/jacksonliam/mjpg-streamer.git
  3. cd mjpg-streamer/mjpg-streamer-experimental
  4. export LD_LIBRARY_PATH=.
  5. make
  6. ./mjpg_streamer -i “./input_raspicam.so -fps 5” -o “./output_http.so”
  7. edit-add a secition ~/.octoprint/config.yaml
    webcam:
    
     stream: http://<your Raspi's IP>:8080/?action=stream
    
     snapshot: http://127.0.0.1:8080/?action=snapshot
    
     ffmpeg: /usr/bin/ffmpeg
    
    
    system:
      actions:
      - name: Shutdown
        command: sudo shutdown -h now
        action: shutdown
        confirm: You are about to shutdown the system.
      - name: Reboot
        command: sudo shutdown -r now
        action: reboot
        confirm: You are about to reboot the system
  8. auto-start camera streamercreate file: /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

    create file: /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
  9. Make it executable
    chmod +x /home/pi/scripts/webcam
    chmod +x /home/pi/scripts/webcamDaemon

Octo Print automatic Startup

sudo cp ~/OctoPrint/scripts/octoprint.init /etc/init.d/octoprint
sudo chmod +x /etc/init.d/octoprint
sudo cp ~/OctoPrint/scripts/octoprint.default /etc/default/octoprint

Edit /etc/default/octoprint

Remove comment from section:

DAEMON=/home/pi/OctoPrint/venv/bin/octoprint

sudo update-rc.d octoprint defaults

edit /etc/rc.local

add section

/home/pi/scripts/webcam start

 Usage

sudo service octoprint {start|stop|restart}
/home/pi/scripts/webcam start

Share with: