January 30, 2018
Multiple Printers on Octoprint
First we create multiple instances of octopi itself.
sudo su - cd /home/pi cp .octoprint .printer1 cp .octoprint .printer2
cd /etc/init.d
update-rc.d -f octoprint remove
cp octoprint printer1
cp printer1 printer2
cd /etc/default
cp octoprint printer1
cp octoprint printer2
Now we edit some files.
vi printer1
# Configuration for /etc/init.d/printer1
# The init.d script will only run if this variable non-empty.
OCTOPRINT_USER=pi# To what host to bind daemon, default is 127.0.0.1
HOST=127.0.0.1# On what port to run daemon, default is 5000
PORT=5000# Path to the OctoPrint executable, use this to override the default setting “/usr/bin/octoprint”
DAEMON=/home/pi/oprint/bin/octoprint# The BaseDir for octopi
BASEDIR=/home/pi/.printer1# What arguments to pass to octoprint, usually no need to touch this
DAEMON_ARGS=“—host=$HOST —port=$PORTi —basedir=$BASEDIR“# Umask of files octoprint generates, Change this to 000 if running octoprint as its own, separate user
UMASK=022# Should we run at startup?
START=yes
vi printer2
# Configuration for /etc/init.d/printer2
# The init.d script will only run if this variable non-empty.
OCTOPRINT_USER=pi# To what host to bind daemon, default is 127.0.0.1
HOST=127.0.0.1# On what port to run daemon, default is 5001
PORT=5000# Path to the OctoPrint executable, use this to override the default setting “/usr/bin/octoprint”
DAEMON=/home/pi/oprint/bin/octoprint# The BaseDir for octopi
BASEDIR=/home/pi/.printer2# What arguments to pass to octoprint, usually no need to touch this
DAEMON_ARGS=“—host=$HOST —port=$PORTi —basedir=$BASEDIR“# Umask of files octoprint generates, Change this to 000 if running octoprint as its own, separate user
UMASK=022# Should we run at startup?
START=yes
cd /etc/init.d vi printer1
Here we edit the files header information leaving the rest alone.
#!/bin/sh
### BEGIN INIT INFO
# Provides: octoprint
# Required-Start: $local_fs networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OctoPrint daemon
# Description: Starts the OctoPrint daemon with the user specified in
# /etc/default/printer1.
### END INIT INFO# Author: Sami Olmari
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=”OctoPrint Printer1″
NAME=“Printer1″
DAEMON=/usr/bin/octoprint
PIDFILE=/var/run/$NAME.pid
PKGNAME=printer1
SCRIPTNAME=/etc/init.d/$PKGNAME
vi printer2
#!/bin/sh
### BEGIN INIT INFO
# Provides: octoprint
# Required-Start: $local_fs networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OctoPrint daemon
# Description: Starts the OctoPrint daemon with the user specified in
# /etc/default/printer2.
### END INIT INFO# Author: Sami Olmari
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=”OctoPrint Printer2″
NAME=“Printer2″
DAEMON=/usr/bin/octoprint
PIDFILE=/var/run/$NAME.pid
PKGNAME=printer2
SCRIPTNAME=/etc/init.d/$PKGNAME
update-rc.d printer1 defaults update-rc.d printer2 defaults
Now you have options on how to access the instances.  Haproxy is already setup and since names area easier to remember we’ll go with that.  This example allows the simple printer1 or printer1.x. I am also including the cam options, you may not use them but if the cam isn’t there you simply get the 503 error.
cd /etc/haproxy vi haproxy.cfg
# this is a test #
global
maxconn 4096
user haproxy
group haproxy
log 127.0.0.1 local1 debugdefaults
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 15minfrontend public
bind *:80
bind *:443 ssl crt /etc/ssl/snakeoil.pem
option forwardfor except 127.0.0.1acl printer1_host hdr(host) -i -m beg printer1
acl printer2_host hdr(host) -i -m beg printer2
acl webcam path_beg /webcam/use_backend printer1_cam if printer1_host webcam
use_backend printer2_cam if printer2_host webcamuse_backend badger1 if printer1_host
use_backend badger2 if printer2_hostbackend printer1
reqrep ^([^\ :]*)\ /(.*) \1\ /\2
option forwardfor
server octoprint1 127.0.0.1:5000
errorfile 503 /etc/haproxy/errors/503-no-octoprint.httpbackend printer2
reqrep ^([^\ :]*)\ /(.*) \1\ /\2
option forwardfor
server octoprint2 127.0.0.1:5001
errorfile 503 /etc/haproxy/errors/503-no-octoprint.httpbackend printer1_cam
reqrep ^([^\ :]*)\ /webcam/(.*) \1\ /\2
server webcam1 127.0.0.1:8080
errorfile 503 /etc/haproxy/errors/503-no-webcam.httpbackend printer2_cam
reqrep ^([^\ :]*)\ /webcam/(.*) \1\ /\2
server webcam2 127.0.0.1:8081
errorfile 503 /etc/haproxy/errors/503-no-webcam.http
I’m going to move from here into getting the serial ports so they don’t move around on you.  Using udev we can set rules that give us a symlink to the ports.  Plug in printer1 to the USB.
udevadm info /dev/ttyACM0
Here we want to take note of the ID_VENDOR, ID_ID_MODEL_ID, ID_SERIAL_SHORT. Â We will use those items to pin down the device as it is connected and create a symlink to it no mater what order it happens to be recognized or if it gets unplugged and re-ordered. Â Plugin the second printer and run the command against the second port making note of the same items.
udevadm info /dev/ttyACM1 cd /etc/udev/rules.d/ vi 99-com.rules
in here we add a line for each printer like the following
SUBSYSTEM==“ttyâ€, ATTRS{idVendor}==“ID_VENDOR_IDâ€, ATTRS{idProduct}==“ID_MODEL_ID”, ATTRS{serial}==”ID_SERIAL_SHORT”, SYMLINK+=”printer1″
SUBSYSTEM==“ttyâ€, ATTRS{idVendor}==“ID_VENDOR_IDâ€, ATTRS{idProduct}==“ID_MODEL_ID”, ATTRS{serial}==”ID_SERIAL_SHORT”, SYMLINK+=”printer2″
This gives us a symlink in /dev for /devprinter1 and /dev/printer2.  Octoprint won’t recognize these ports however so they must be added to each instance manually.
cd /home/pi/.printer1 vi config.yaml
Here you want to search for serial: you can do that by typing /serial and pressing enter. Â It should look like the following.
serial:
additionalPorts:
– /dev/printer1
autoconnect: true
baudrate: 250000
port: /dev/printer1
Do the same for printer2. Â You may also want to locate the webcam config for printer2 and modify the port to 8081 should you want to add a camera to the setup
webcam:
ffmpeg: /usr/bin/avconv
snapshot: http://127.0.0.1:8081/?action=snapshot
stream: /webcam/?action=stream
Now reboot the system.  If you’ve followed everything and you have printer1 and printer2 mapped in your domain to the ip on the octopi you should be able to access them both.
If you want to have cameras on each printer you will need to configure the daemons and have them listening and there are several ways to get cameras from the official rapicam, generic usb cam or external ip cam. Â The example here is just a basic usb cam setup and would need to be modified for any of the other scenarios.
update-rc.d -f webcamd remove cp webcamd printer1webcamd cp webcamd printer2webcamd update-rc.d printer1webcamd defaults update-rc.d printer2webcamd defaults vi printer1webcamd
Here we want to modify the areas to printer1
#!/bin/sh
### BEGIN INIT INFO
# Provides: printer1webcamd
# Required-Start: $local_fs networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: printer1 webcam daemon
# Description: Starts the OctoPi webcam daemon with the user specified config in
# /etc/default/printer1webcamd.
### END INIT INFO# Author: Gina Haeussge
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=”Webcam Daemon”
NAME=“printer1webcamd”
DAEMON=/root/bin/printer1webcamd
USER=pi
PIDFILE=/var/run/$NAME.pid
PKGNAME=printer1webcamd
SCRIPTNAME=/etc/init.d/$PKGNAME
LOG=/var/log/printer1webcamd.log
Repeat the same edits for pritner2cam.
cd /root/bin cp webcamd printer1webcamd cp webcamd printer2webcamd vi printer1webcamd
We are going to edit two options here the camera_usb_options and camera_http_options and comment out the octopi overrides.
camera_usb_options=“-d /dev/printer1_video -r 640×480 -f 10″
camera_http_options=”-n -p 8080″
We do the same thing for printer2webcamd and we modify the -p option to 8081.
Now we setup symlinks to the video devices much like we did with the serial ports.
Plug in the first usb cam and run
udevadm info /dev/video0
Here we want to take note of the ID_VENDOR, ID_ID_MODEL_ID, ID_SERIAL_SHORT. Â Plug in the second webcam and do the same for it.
cd /etc/udev/rules.d/ vi 99-com.rules
SUBSYSTEM==“video4linuxâ€, ATTRS{idVendor}==“ID_VENDOR_IDâ€, ATTRS{idProduct}==“ID_MODEL_ID”, ATTRS{serial}==”ID_SERIAL_SHORT”, SYMLINK+=”printer1_video”
SUBSYSTEM==“video4linuxâ€, ATTRS{idVendor}==“ID_VENDOR_IDâ€, ATTRS{idProduct}==“ID_MODEL_ID”, ATTRS{serial}==”ID_SERIAL_SHORT”, SYMLINK+=”printer2_video”
Once you have done this you want to reboot to reload the ini scripts and re-run udev rules.