Multiple printers per server megathread


#1

Pis are cheap, human time is expensive (especially when multiplied by the number of people reading a message), and there are plenty of reasons that multiple instances of OctoPrint on one Pi is problematic.

Because of that, "we" don't support it. This thread will be the only place that discussion about it is allowed, and any support is given as best-effort, not "omg there's a bug and I'm going to @ a developer".


Multiple instances of Octoprint on a single RPi
One RPi, multiple different printers. Is there a way to bind Serial port to profile and slicer-profile?
Could we get a multi printer multi camera octopi rasp pi image?
Multiple Printers and Connection Issues
Multiple Instances of Octoprint on Linux
Setting up OctoPrint on a Raspberry Pi for multiple printers
Multiple printers, USB doesn't recognize all of them
#2

Just a link for now to a guide that works
Setting up OctoPrint on a Raspberry Pi for multiple printers

A couple of notes from my own experience following this guide.
Adding a second webcam
99-usb.rules:
If you have two of the exact same webcams the filtering doesn't work if your camera doesn't have a serial number, mine didn't.
Workaround: Use a USB hub, on the hub I used each port had its own identifier under the KERNALS tag
KERNELS=="1-1.2.1" and KERNELS=="1-1.2.2" for my hub was port 1 and 2

/root/bin/webcamd and webcamd2
I recommend using 8081 for webcamd and 8082 for webcamd2

Also I needed to comment out these lines in webcamd and webcamd2

if [ -e "/boot/octopi.txt" ]; then
    source "/boot/octopi.txt"
fi

so like this

#if [ -e "/boot/octopi.txt" ]; then
#    source "/boot/octopi.txt"
#fi

/etc/haproxy/haproxy.cfg
Because of the above change, the haproxy needs to be a little different. Notice the ports in the backend.
This is mine as an example

global
        maxconn 4096
        user haproxy
        group haproxy
        tune.ssl.default-dh-param 1024
        log 127.0.0.1 local1 debug

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

frontend public
        bind *:80
        option forwardfor except 127.0.0.1
        acl host_CR10-A hdr_beg(host) -i CR10-A
        acl host_CR10-B hdr_beg(host) -i CR10-B
        use_backend webcam if { path_beg /webcam/ } host_CR10-A
        use_backend webcam2 if { path_beg /webcam/ } host_CR10-B
        use_backend octoprint if host_CR10-A
        use_backend octoprint2 if host_CR10-B
        default_backend octoprint
        errorfile 503 /etc/haproxy/errors/503-no-octoprint.http

backend octoprint
        reqrep ^([^\ :]*)\ /(.*) \1\ /\2
        reqadd X-Scheme:\ https if { ssl_fc }
        option forwardfor
        server octoprint1 127.0.0.1:5000

backend octoprint2
         reqrep ^([^\ :]*)\ /(.*) \1\ /\2
         reqadd X-Scheme:\ https if { ssl_fc }
         option forwardfor
         server octoprint2 127.0.0.1:5001

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam1  127.0.0.1:8081

backend webcam2
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam2  127.0.0.1:8082
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

And for accessing outside the network because of how I setup my haproxy I only need one port open, 81
image

I am using my domain, with an a record to point to my home ip address
image

The haproxy rules work like this for me
http://cr10-a.mydomainname.com:81 takes me to backend octoprint, my first printer
http://cr10-b.mydomainname.com:81 takes me to backend octoprint2, my second printer
http://cr10-a.mydomainname.com:81/webcam/ takes me to backend webcam, my first printers webcam
http://cr10-b.mydomainname.com:81/webcam/ takes me to backend webcam2, my second printers webcam
http://cr10-a.mydomainname.com:81/webcam/?action=stream takes me to backend webcamstream, my first printers webcam stream
http://cr10-b.mydomainname.com:81/webcam/?action=stream takes me to backend webcamstream2, my second printers webcam stream

That's about it.


#3

Thanks for a great guide. I'm still with a single printer right now but hoping to add another a little later this year :crossed_fingers: so this should be helpful.


#4

Have you tried integrating a common directory for your gcode files the instances can share?


#5

I have not, I've been a bit AFK from my printers actually.


#6

So I've followed this to a T, but I can't seem to get the second instance to work.
I have it set in haproxy so that:
https://xlaitsnet.tk/ender/ takes you to the page for my Ender 3
https://xlaitsnet.tk/startt/ SHOULD take you to my STARTT.

However, the STARTT doesn't want to work, and shows a 503 error when accessing the page.
What logs or files do I need to show for some help? I'm not sure where to start.


#7

Did you have any luck resolving this?


#8

I did, but I have no idea what I actually did to fix it.


#9

What is the problem?
I've followed this guide here (https://www.youtube.com/watch?v=7Saa1HpLRoM&t=2s) to set up two instances of octoprint so both my CR10's are able to communicate with a single PI. Everything works perfectly in 1.3.8, but as soon as I update to 1.3.10, octoprint is stuck trying to connect to the printers, and any changes I am able to make in the settings does nothing. Seems almost unresponsive.

What did you already try to solve it?
All I've done is reinstall a couple times to make sure that I didn't mess something up in putty. Not sure how to tackle the issues honestly. Seems a bit outside of my realm.

I've done this three times:
First time, I did a fresh install, updated octoprint, and made the modifications through putty. Didn't work.
Second time, I did a fresh install, didn't update octoprint, made the modifications through putty, and it worked perfectly. Once it was working, I updated octoprint to 1.3.10, and it bricked. Wouldn't connect.
Third time I did a fresh install, and didn't update octoprint once again. It's working fine, but I'm currently keeping in 1.3.8 because I don't want to brick it yet again.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)

I'm using two CR10's with standard firmware. Was planning to update once I got both instances working. Have yet to update.

Upon installing octoprint, these are the commands I used in putty to create the second instance (basically TL;DR for the video):

sudo su

cd /etc/init.d

sed s/octoprint/octoprint2/ < octoprint | sed s/OctoPrint/OctoPrint2/ | sed s/bin\/octoprint2/bin\/octoprint/ > octoprint2

chmod 755 octoprint2

cd /etc/default

sed s/PORT=5000/PORT=5001/ < octoprint | sed s/HOST=127.0.0.1/HOST=0.0.0.0/ | sed s/$PORT/$PORT\ --basedir\ \/home\/pi\/.octoprint2/ > octoprint2

sudo update-rc.d octoprint2 defaults 99

sudo reboot now

With both instances created, I set up both profiles for my CR10's. Then I had to route the serial ports to control each printer:

cd /var/log

sudo cat messages

Looked for the USB to identify which is which, and added rules using:

sudo nano /etc/udev/rules.d/99-usb.rules

SUBSYSTEM=="tty";, ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="XXXX", ATTRS{devpath}=="X.X", SYMLINK+="PrinterName"

Saved the rules. Used ls -l /dev to make sure the printers were routed correctly. They were. Went into each instance of octoprint and added the additional serial ports (PrinterName) and chose those for the port. Both were connected and speaking to the printers. Once that was working, I updated. This caused the printers to disconnect, and then when attempting to reconnect (which it did automatically), both instances just seemed stuck in a loop- unable to connect. I am unable to click on any of the information in the "connection" window on the home screen, except for the disconnect button. But when I press the disconnect button, nothing happens. I'm also not able to click any buttons within the additional tabs (control, temp, gcode, etc), all that shows is a red circle with a slash through it. I am able to go into the settings and change some of the connection settings, but it doesn't change anything..

This is a snippet from octoprint.log:

2019-02-04 21:48:03,996 - octoprint.server.util.sockjs - INFO - Client connection closed: ::ffff:IPADDRESS
2019-02-04 21:48:05,661 - octoprint.server.util.sockjs - INFO - New connection from client: ::ffff:IPADDRESS
2019-02-04 21:48:05,750 - octoprint.server.util.flask - INFO - Passively logging in user USERNAME from ::ffff:IPADDRESS
2019-02-04 21:48:09,177 - tornado.general - ERROR - WebSocket
Traceback (most recent call last):
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/vendor/sockjs/tornado/transports/websocket.py", line 61, in on_message
self.session.on_messages(msg)
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/vendor/sockjs/tornado/session.py", line 419, in on_messages
self.conn.on_message(msg)
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/util/sockjs.py", line 172, in on_message
message["auth"]))
ValueError: unmatched '{' in format

This message repeats for about 50k lines. The ValueError seems like a flag to me from my coding experience, but octoprint is much more complex than anything I've written so, no idea if it's actually a flag.

Only information available from serial.log is this:

2019-02-04 21:43:40,027 - serial.log is currently not enabled, you can enable it via Settings > Serial Connection > Log communication to serial.log
2019-02-04 22:21:02,346 - Enabling serial logging

Sorry for the wall of text. Trying to be as thorough as possible. That's all the information I have available. Thoughts? Lol.


#10

Multiple printers per 'server' is not supported. The cost of a second Pi is much less than the time required to offer support. You're welcome to experiment with it, but we don't endorse or support it.


#11

Using a (1, one) raspberry pi with octoprint, with multiple different 3D printers.
Is there a way to bind: slicer(cura)-profile + Serial port, per profile?

Searching plugins, looking through settings in webgui. google...

Octopi 1.3.9
Raspberry Pi 3+
2 Ender 3
1 Ender 2
1 Creality CR-10 S5


#12

use multiple instances.
1 Instance for 4 printers makes no sense because you only can print with one.

when you use no cams then it should work on a rpi3


#13

Thx for the reply! =)

I'll try that.

...hm..why does people call the dist "3D printer server"? More like "3D printer access point"... =P


#14

The snappy web interface for your 3D printer.

singular -> one printer

it is a 3d print host software which has a webinterface.


#15

Because it's a server and not an access point
An access point just hands over data and nothing more
A server stores data, can react to user commands and more


#16

What is the problem?

503 Errors while attempting to access 2nd printers' page
Unable to name USB ports.
Printers connection randomly timing out if left idle.

What did you already try to solve it?

Changed HAproxy settings to every solution known to google.
Changed second instance settings to every solution known to google.

Changing udev rules several times.

Adjusted long-running command time.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)

OctoPi version 1.3.9
Raspberry Pi 3 B+
Creality Ender 3
iMaker STARTT

I don't have access to the logs at this moment, I will post them when I can, if required.


#17

Are you set up with one pi or two?


#18

My setup is exactly 1 (one) pi.


#19

So are you trying to run multiple instances on the same pi or multiple printer on the same instance?


#20

Multiple instances, as implied by the "HAproxy config" and "503 error on 2nd printer page" mentions in the OP.