Die Grundinstallation des Raspberry Pi wurde im vorherigen Teil abgeschlossen. Jetzt kommt die Installation des Druckservers Octoprint dran.

Einrichtung von Octoprint

Octoprint User hinzufügen

Da ich gerne die Dienste als eigener User laufen lasse, wird ein neuer Benutzer eingerichtet.

$ sudo useradd -c "Octoprint User" -m -U -G tty,dialout,sudo,audio,video,users,input,netdev,gpio,i2c,spi -s /bin/bash octoprint
$ sudo passwd octoprint
$ echo "octoprint ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/011_octoprint-nopasswd
$ sudo apt update
$ sudo apt install python-pip python-dev python-setuptools python-virtualenv git libyaml-dev build-essential
$ git config --global user.email "sven@paass.net"
$ git config --global user.name "Sven Paaß"

$ sudo su - octoprint
$ git config --global user.email "sven@paass.net"
$ git config --global user.name "Sven Paaß"

$ git clone https://github.com/foosel/OctoPrint.git
$ cd OctoPrint
$ virtualenv venv
$ source venv/bin/activate

$ pip install --upgrade pip
$ pip install .

# Python Bonjour installieren für das Discovery Plugin
$ pip install -e git+https://github.com/Eichhoernchen/pybonjour.git#egg=pybonjour
Testen
$ ~/OctoPrint/venv/bin/octoprint serve

Der Octoprint Server sollte normal starten und auf Port 5000 horchen. (das findet man in den Log-Ausgaben)

octoprint.server - INFO - Listening on http://[::]:5000

Danach kann man den Server mittels Ctrl-C beenden.

Octoprint Autostart einrichten
$ sudo cp scripts/octoprint.init /etc/init.d/octoprint
$ sudo cp scripts/octoprint.default /etc/default/octoprint
$ sudo chmod +x /etc/init.d/octoprint
  • Die Datei /etc/default/octoprint anpassen:
OCTOPRINT_USER=octoprint
BASEDIR=/home/octoprint/.octoprint
CONFIGFILE=/home/octoprint/.octoprint/config.yaml
DAEMON=/home/octoprint/OctoPrint/venv/bin/octoprint

Den Server als Autostart-Objekt einfügen:

$ sudo update-rc.d octoprint defaults
HA-Proxy einrichten
$ sudo apt install haproxy
  • /etc/haproxy/haproxy.cfg (anpassen bzw. anhängen)
defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        option http-server-close
        option forwardfor
        maxconn 2000
        timeout connect 5s
        timeout client  15min
        timeout server  15min
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http

frontend public
        bind :::80 v4v6
        use_backend webcam if { path_beg /webcam/ }
        default_backend octoprint
    stats enable  # Enable stats page
    stats hide-version  # Hide HAProxy version
    stats realm Haproxy\ Statistics  # Title text for popup window
    stats uri /stats  # Stats URI
    stats auth octoprint:octoprint  # Authentication credentials

backend octoprint
        reqrep ^([^\ :]*)\ /(.*)     \1\ /\2
        option forwardfor
    option httpchk
        server octoprint1 127.0.0.1:5000 check

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
    option tcp-check
        server webcam1  127.0.0.1:8080 check

Den HA-Proxy Server starten:

$ sudo /etc/init.d/haproxy restart
CuraEngine installieren
$ cd ~
$ git clone -b legacy https://github.com/Ultimaker/CuraEngine.git
$ cd CuraEngine
$ make
Webcam einrichten
$ cd ~
$ sudo apt install libjpeg62-turbo-dev imagemagick ffmpeg libv4l-dev cmake
$ git clone https://github.com/jacksonliam/mjpg-streamer.git
$ cd mjpg-streamer/mjpg-streamer-experimental
$ make
Testen:
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so"
oder
./mjpg_streamer -i "./input_raspicam.so" -o "./output_http.so"
  • URL http://ip-des-raspberry/webcam/?action=stream öffnen
Startskript
$ mkdir -p ~/scripts
  • ~/scripts/webcam
#!/bin/bash
# Start / stop streamer daemon

case "$1" in
    start)
        /home/octoprint/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
  • ~/scripts/webcamDaemon
#!/bin/bash

MJPGSTREAMER_HOME=/home/octoprint/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
$ chmod +x /home/octoprint/scripts/webcam
$ chmod +x /home/octoprint/scripts/webcamDaemon
  • /boot/octopi.txt erstellen
# octoprint camera configuration
camera="raspi"
camera_usb_options="-r 1280x720 -f 25"
camera_raspi_options="-fps 5 -x 1280 -y 720 -quality 100 -usestills -ISO 100 -ev -0.5 -ex spotlight -awb fluorescent -mm matrix"
  • In der Datei /etc/rc.local die Webcam starten (vor exit 0 einfügen):
    su - octoprint -c "/home/octoprint/scripts/webcam start"

    exit 0
$ sudo su - octoprint -c "/home/octoprint/scripts/webcam start"
$ sudo service octoprint start
$ cd ~
  • http://ip-des-raspberry/ aufrufen und OctoPrint konfigurieren
- Zugangsbeschränkung aktivieren
- Onlineprüfung aktivieren
- Pluginblackliste aktivieren
- CuraEngine (<= 15.04)
  - Pfad: /home/octoprint/CuraEngine/build/CuraEngine
  - Profil hochladen
- Default Druckerprofil
  - Allgemein
    - Name: ANET
    - Modell: A6
  - Druckbett & -volumen
    - Formfaktor: Rechteckig
    - Ursprung: Unten links
    - Heizbett: Ja
    - Breite (X): 220mm
    - Tiefe (Y): 220mm
    - Höhe (Z): 230mm   
  - Achsen
    - X: 1000mm/min
    - Y: 1000mm/min
    - Z: 100mm/min
    - E: 100mm/min
  - Hotend & Extruder
    - Düsendurchmesser: 0.4
    - Anzahl Extruder: 1

- Serverbefehle
  - OctoPrint neustarten: sudo service octoprint restart
  - System neustarten: sudo shutdown -r now
  - System herunterfahren: sudo shutdown -h now

- Webcam & Zeitraffer
  - Stream- URL: /webcam/?action=stream
  - Snapshot-URL: http://127.0.0.1:8080/?action=snapshot
  - Pfad zu FFMPEG: /usr/bin/ffmpeg

Octoprint stoppen und den Server nur auf der lokalten Schnittstelle horchen lassen:

$ sudo service octoprint stop
- ~/.octoprint/config.yaml anpassen:
server:
  host: 127.0.0.1

system:
  actions:
   - action: streamon
     command: /home/octoprint/scripts/webcam start
     confirm: false
     name: Start video stream
   - action: streamoff
     command: /home/octoprint/scripts/webcam stop
     confirm: false
     name: Stop video stream
Discovery Plugin nutzen
$ sudo apt install libavahi-compat-libdnssd-dev
Swap-Size erhöhen (2GB)
$ sudo sed -i '/^CONF_SWAPSIZE.*/s//CONF_SWAPSIZE=2048/' /etc/dphys-swapfile
$ sudo reboot
OctoPrint Plugins installieren
- OctoPrint öffnen und einloggen
- Einstellungen öffnen -> Pluginmanager -> Mehr ...

- "octolapse" suchen und installieren ("Fehler" beim Pillow wheel -> Nochmal)
  - OctoPrint neu starten

- Konfiguration Octolapse:
  - Printer: Anet A8 - Beta
  - Stabilization: Fixed - Extruder at Center
  - Snapshot: Layer Change
  - Rendering:
    - MP4 - 30 FPS
    - MP4 - Fixed Length - 00:15
    - eigenes Template erstellen (Einstellungen->OctoPrint->Rendering->Add Profile...)
      - Name: MP4 - 25 FPS - 1s pre / 5s post
      - Description: Generates MP4 with a fixed framerate of 25 frames per seconds. Adds 1 second of pre-roll using the first frame and five seconds post-roll using the last frame.
      - Timelapse Generation: On
      - Output File Format: MP4
      - Sync Output: On
      FPS Type: Static FPS
      Static FPS: 25
      Pre-Roll: 1
      Post-Roll: 5
      Bitrate: 5000k
  - Camera: Default Webcam
  - Debug: No Logging

- "DisplayLayerProgress"
  - Show printer display on Desktop -> aus
  - Navigationsmenü: aus
  - Drucker Anzeige: aus

- "Fan Speed Control"

- "Firmware Updater"
  - $ sudo apt install avrdude

- exit (Octoprint User abmelden)

Nächster Beitrag Vorheriger Beitrag