laitimes

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

author:Xiaoping

preface

3D printers generally have two ways to play, one is to make 3D printers a productivity tool and print a variety of fun models; The other is to play with the 3D printer itself, including retrofitting the 3D printer, optimizing the 3D printer, trying various different types of 3D printers, and even DIY a 3D printer from scratch. At present, among the domestic 3D printer manufacturers, Tuozhu can be described as unique, although its products are more expensive, but the printing speed and printing quality are amazing. As a user of Topbamboo P1P, I am deeply impressed by this. Topbamboo P1P can become my productivity tool stably and efficiently, which gives me the opportunity to experience the other half of the fun of 3D printers - DIY 3D printers.

The difficulty of DIY 3D printers should be the upper limit that ordinary people can understand and complete. That is to say, the average person, may not need much professional knowledge, with the rich information on the Internet and a variety of standard kits readily available on Taobao, as long as there is patience, it is possible to successfully assemble a 3D printer. At present, the most popular high-performance 3D printing firmware should be klipper. A 3D printer based on klipper not only has a lower computer controller as the core of various motors and sensors, but also a host computer that undertakes complex calculations and provides a visual UI interface. The lower computer is like the heart of the 3D printer, generally based on the STM32 embedded development board, while the upper computer is a Linux-based computer, as long as it can communicate with the lower computer through the USB connection for serial communication.

When assembling a 3D printer, most players generally choose a Raspberry Pi or a development board with equivalent computing power as a host computer. Some will choose TV boxes, old mobile phones and so on in order to save costs. NAS is essentially a Linux-based computer, also has a USB interface, as far as I understand, NAS players and 3D printing players have a fairly high degree of overlap, then using NAS as a 3D printer host computer is also a good choice, as long as NAS and 3D printers leave a suitable space for placement.

QNAP NAS installs Klipper

The method described in this article is based on QNAP's x86 flat station-based NAS device, and other brands and architectures of NAS may not be applicable. QNAP's operating system QTS is Linux, but Klipper is not easily installed directly on QTS, although it is theoretically possible. So to install Klipper, you naturally think of a virtualization-based solution. That's where QNAP's three virtualization solutions: Container Station, Ubuntu Station and Virtualization Station come in handy.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

Scenario selection

  • Under normal circumstances, most users will choose to use Container Station, because this is the most lightweight solution, and there are currently ready-made docker images to choose from (https://github.com/dimalo/klipper-web-control-docker), but there are problems such as the inability to compile Klipper's lower computer firmware and the inability to easily upgrade.
  • Excluding Container Station, you may want to consider Ubuntu Station, although slightly heavyweight, but fortunately efficient in operation. However, I tried it, and after the lower computer was connected to the NAS, there were some problems with the penetration of the USB serial port in the Ubuntu Station, which caused Klipper to lose access to the serial port.
  • Then the final choice is only Virtualization Station, although it is not only heavyweight and slightly less efficient, but my TS-464C performance is still okay, without a lot of pressure. However, after Virtualization Station installs Klipper, there will also be a problem that USB cannot be automatically assigned to the virtual machine, but there is a solution for this.

Linux system installation

Below, let's explain in detail how to install Klipper on Virtualization Station and how to solve the problem. The first step is definitely to create a new Linux instance on the virtual machine.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

When it comes to choosing a Linux distribution, the average person chooses Ubuntu. However, in order to save a little system resources, I chose a lightweight version of Linux Lite (https://www.linuxliteos.com/download.php) based on Ubuntu, which is not much different from Ubuntu. The installation steps of Linux Lite will not be repeated, they are all basic operations, just wait patiently for a while.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

After the system installation is completed, the first thing to do is to replace the official software source to speed up the download and installation of the software. The latest Linux Lite 6.4 is based on Ubuntu 22.04, so the software source replacement method is also the same as Ubuntu 22.04, follow the steps to enter the following commands.

Back up the official software repository and run the following command:

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak           

Replace with Tsinghua University ubuntu 22.04 image:

sudo bash -c "cat << EOF > /etc/apt/sources.list && apt update 
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
EOF"           

Since many of the software to be installed in the future is developed based on Python, it is also necessary to replace the pip source of Python, and enter the following command according to the steps.

mkdir ~/.pip           

Open the configuration file ~/.pip/pip.conf and modify it as follows:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn           

Klipper installation

The basic work is ready. To install Klipper, we need to use kiauh, an automated installation script. With this script, installing dependencies, downloading software, and configuring services do not require too much intervention, all integrated in the script, which is very convenient to use. The code for the Kiauh script is hosted on GitHub, so you need to install the Git tool first.

sudo apt-get install git -y           

Then use the command below to download Kiauh to the user directory.

cd ~ && git clone https://github.com/th33xitus/kiauh.git           

Finally, just run the script directly.

./kiauh/kiauh.sh           

Then we need to select the software to install according to the pop-up menu prompts. Here, we need to install three pieces of software: Klipper, Moonraker, and Fluidd. How to understand the relationship between the three: Klipper is the firmware of the 3D printer, Moonraker is a web service developed based on Python, which can interact with Klipper and provide APIs, and Fluidd is the web UI front-end, using the APIs provided by Moonraker to indirectly control Klipper, operate and monitor the 3D printer in a graphical way.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

With Kiauh, installing these software is incredibly easy, and the only roadblock may be poor access to GitHub due to network issues. The solution is either to hang a ladder or to try a few more times. In order, we install Klipper, Moonraker, and Fluidd. If needed, you can also replace Fluidd with another front-end Mainsail, and if the printer has a screen, you can choose to continue installing KlipperScreen.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper
For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

After the software installation is configured, use the IP of the virtual machine to access it directly, and you can see the Fluidd page without accident.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper
For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

For different 3D printer hardware configurations, we also need to compile the firmware for the lower computer, flash the firmware, and configure in detail in Fluidd. This part is different for every printer and is beyond the focus of this article, so I skipped it. My current situation is that the lower computer firmware has been burned and I already have the correct configuration file. At this time, because the NAS has not yet been connected to the main control board of the lower computer, the 3D printer device cannot be seen. Connect the NAS and the lower computer main control board with USB, and QTS should be able to directly identify the lower computer. If you want the virtual machine to recognize the lower computer motherboard, you need to manually pass the USB device directly into the virtual machine.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

In this way, the device can be seen inside the virtual machine. Configure the device path to Fluidd's configuration file, and Fluidd can correctly recognize the 3D printer main control board.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper
For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

USB automounting

At this time, there will be a problem, if the 3D printer main control board is powered down, the USB device will not be automatically loaded into the virtual machine. If it's not too troublesome, you need to manually click it every time, but this is obviously too inelegant. If you can plug in a designated USB device and automatically load it into the specified virtual machine, then everything is perfect.

To solve this problem, below, it is time to show some little tricks. First ssh login to the NAS terminal, 3D printer powered on, lower computer motherboard connected to NAS, enter lsub to view the newly inserted device, note the vendor ID and product ID of the device. Such a result as I am here. OpenMoko is the newly plugged device, 1d50 is the vendor ID, and 614e is the product ID.

[~] # lsusb
Bus 001 Device 002: ID 0463:ffff MGE UPS Systems UPS
Bus 001 Device 003: ID 1d50:614e OpenMoko, Inc. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub           

.xml create a new file mount, enter the following, the key is vendor id and product id. Files are created in any shared directory, remember this path.

<hostdev mode = 'subsystem' type = 'usb' managed = 'yes'>
   <source>
      <vendor id='0x1d50'/>
      <product id='0x614e'/>
   </source>
</hostdev>           

Next, look at the uuid of the Linux virtual machine instance that is currently running in Virtualization Station and note this value.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

With the virtual machine instance running normally, enter the following command in the NAS terminal:

/QVS/usr/bin/virsh attach-device your_uuid  /share/Share/mount.xml           

At this point, go back to your Linux virtual machine terminal and check if the USB device loads correctly. If you load correctly, you're halfway there, and it's now at least proven that USB devices can be pass-through to a virtual machine via the command line. Copy the above command into a new script file mount.sh.

#! /bin/sh -x
export LD_LIBRARY_PATH=/QVS/usr/lib:/QVS/usr/lib64/ 
export PATH=$PATH:/QVS/usr/bin/:/QVS/usr/sbin/
/QVS/usr/bin/virsh attach-device your_uuid  /share/Share/mount.xml           

and give the script executable permissions

chmod +x /share/Share/mount.sh           

Then the next thing to solve is to plug in the USB device and automatically pass through to the virtual machine. Go back to the NAS terminal and enter the command.

udevadm monitor --env           

Plug and unplug the USB cable of the lower computer, at this time, there will be many kernel udev events reported, note the DEVPATH of the corresponding add event. The event information output looks similar to the following.

UDEV  [17933.644086] add      /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0
DEVTYPE=usb_interface
INTERFACE=2/2/1
MODALIAS=usb:v1D50p614Ed0100dc02dsc00dp00ic02isc02ip01in00
PRODUCT=1d50/614e/100
SEQNUM=2783
SUBSYSTEM=usb
TYPE=2/0/0
USB_1_2=UPS_HID
USEC_INITIALIZED=17933635952
mmc0_0001=root_boot
sg0=root
sg1=root
sg2=root
sg3=root           

Create a new text file 99-usbshare.rules and fill in the following. DON'T COPY, YOUR DEVPATH MAY BE DIFFERENT.

ACTION=="add",DEVPATH=="/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0",RUN+="/share/Share/mount.sh",OPTIONS+="last_rule"           

Then create a new script autorun.sh and fill in the following:

#! /bin/sh
cp -f /share/qnap/99-usbshare.rules /lib/udev/rules.d/
udevadm control --reload-rules
udevadm trigger           

Here is a brief explanation of what these commands and text files do. First of all, the rule configured in 99-usbshare.rules is that if an action is added and the DEVPATH is reported as a udev event with the specified content, the device is mounted in the virtual machine mount.sh executed. autorun.sh command will put the rule 99-usbshare.rules in the specified directory and reload the rule with the udevadm command to make it effective. So now we give autorun.sh this script executable permissions and run it. Then try to unplug and plug the USB, enter the Linux terminal of the virtual machine, and you should be able to see the responding device node directly.

chmod +x /share/Share/autorun.sh           

The last step is to autorun.sh this script can also be run automatically on boot, so that later rebooting the NAS can also make the lower computer motherboard inserted into the NAS through USB automatically loaded into the corresponding virtual machine, everything once and for all, flawless. We also need to take the following steps. Run the following command in the NAS terminal.

mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config
cp /share/Share/autorun.sh /tmp/config
umount /tmp/config           

Then inside the NAS console--system--hardware, enable the user-defined process at startup.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

In this way, Klipper and its companion software can work perfectly in the NAS. Go to Fluidd to check the status of the 3D printer, then load the supplies and try to print a model.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

3D printer and NAS display

Having seen too many software parts, let's show off my hardware: two 3D printers and a QNAP NAS. The first 3D printer is the Tobamboo P1P, which is currently my main 3D printing productivity tool. As the lowest end product of Tuozhu Technology, it can also be said that the ceiling exists in the current consumer-grade finished 3D printer market. I am very satisfied with the printing speed and print quality of the Topbamboo P1P, sometimes the machine shakes like a washing machine, and it still does not affect the printing quality of the finished product. This is the charm of the combination of excellent structural design and excellent software algorithms.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

The second 3D printer is my own DIY Voron 0.1, which is also the 3D printer used in this article to verify the feasibility of installing Klipper on the NAS. I purchased the kit directly for this machine, and then assembled, screwed, wired, welded, and installed the configuration software bit by bit according to the official instructions, and it took several nights to assemble. Personally, I still really like this Voron 0.1. After all, I built it from scratch. Although the Voron 0.1 print size is not hit, and the printing speed is not too high without deep debugging, the full CNC body plus the cool shape is still very good as a desktop ornament.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper
For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

Finally, let's talk about this QNAP TS-464C NAS, at this time, my newly upgraded NAS device will also be used as my main NAS in the future. TS-464C adopts N5095 processor, 4 cores and 4 threads, the maximum frequency is 2.90GHz clock, single-core performance, multi-core performance and core graphics performance are not bad. With 8GB LPDDR4X 2933 dual-channel on-board memory, although the expansion line is lost, there is no pressure to run a virtual machine plus a few Dockers with 8GB capacity, and I am currently using it this way.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

Four 3.5-inch hard drive slots plus two M.2 hard drive slots are quite conscientious in configuration. Two built-in M.2 2280 PCIe Gen 3 x2 slots, which can support dual M.2 NVMe SSDs, enable caching, improve data computing power and access performance; You can also use Qtier to enable auto-tiered storage technology to maximize storage efficiency.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

In terms of other interfaces, there is a USB 3.2 Gen 2 port on the front and back, and a USB 2.0 port on the back. One HDMI 2.0 port can support up to 4096 x 2160 @ 60Hz video output, creating a must-have interface for HTPC. Dual 2.5GbE interface network transmission, which can support link aggregation (Port Trunking) to achieve transmission bandwidth of up to 5Gbps.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper

At present, QNAP has just released a new TS-466C based on N6005, but the performance improvement is not much compared to the N5095. Before QNAP launched the new N100 series NAS, I estimate that this TS-464C will last a long time.

postscript

Deploying Klipper on a virtual machine isn't that hard, as it can all be easy with kiauh and solving network issues. The difficulty of deploying Klipper using a virtual machine is how to solve the problem of the device being mounted in the virtual machine after USB is plugged and unplugged. While QNAP's Virtualization Station provides a UI menu to perform USB mounts manually, this is obviously too inconvenient. In order to solve this problem, searching Chinese websites did not find answers, and even there were few articles on deploying Klipper with NAS. Eventually I found some clues in English on Google and successfully solved the problem. So let's say it's the first of its kind in China. If you don't want to buy additional PCs, such as Raspberry Pi, Yuzu Pi, etc., and don't want to use cheap TV boxes, Redmi phones to toss, you just have a NAS that can use virtual machines, then you may wish to try deploying Klipper on this. If you don't even have a 3D printer, then get into the pit early 3D printing, it's really fun.

For the first time in China, let NAS become the brain of 3D printers, QNAP NAS perfectly installed klipper