DEV Community

WallClocks
WallClocks

Posted on

Run Klipper/OctoPrint In Void Linux

This is a guide for installing Klipper and Octoprint on Void Linux
octovoid_v1

It is broken into 3 sections,

  1. Installing Klipper
  2. Installing Octoprint
  3. Installing Webcam

Each Section is broken into numbered steps. It is a lot but very dueable, it is mostly copy+paste. That said you should always try and understand what you paste into your console.


Klipper

I am assuming you have a printer.cfg file in your home directory, your printer is connted via USB and you know kinda how to use a terminal.

I have made a new user pi, to keep things as close to the raspberry-pi setup as I can. I recommend you do this as well.

To make a new user

### Login as root
su
# create the new user
useradd -m -G dialout,tty -s /bin/bash pi
Enter fullscreen mode Exit fullscreen mode

make sure the user pi is part of the dialout and tty groups
Add this user to sudoers with visudo command, google if you need help with vi or install nano and run EDITOR=nano visudo from root.

You will need python2 for this to run and python3 to set it up. As of writing this python2 in Void Linux is called python in xbps and python3 is python3. I think they are working on making everything python3 and there is a python3 branch that I have tested and works without Python2 but I am not sure how complete that is.

Now that the user is set up and you are logged in as pi, do the following....

  1. Install system dependencies
sudo xbps-install -S python python3 python3-pip python3-devel python3-setuptools git base-devel libffi-devel libyaml-devel avrdude avr-gcc avr-binutils avr-libc
Enter fullscreen mode Exit fullscreen mode
  1. Clone Klipper Repo from github
cd ~/
git clone https://github.com/Klipper3d/klipper.git klipper
cd klipper
Enter fullscreen mode Exit fullscreen mode
  1. Setup python-venv
python3 -m venv venv
source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode
  1. Install Dependencies
./venv/bin/python -m pip install --upgrade pip
./venv/bin/pip install -r scripts/klippy-requirements.txt
Enter fullscreen mode Exit fullscreen mode
  1. Create runsv service(runit) direcotry and file
sudo mkdir /etc/sv/klipper
sudo touch /etc/sv/klipper/run
sudo chmod +x /etc/sv/klipper/run
Enter fullscreen mode Exit fullscreen mode
  1. Edit the file /etc/sv/klipper/run
#!/bin/bash
export USER=pi
export HOME=/home/pi
groups="$(id -Gn "$USER" | tr ' ' ':')"

exec chpst -u "$USER:$groups" "$HOME"/klipper/venv/bin/python "$HOME"/klipper/klippy/klippy.py "$HOME"/printer.cfg -l /tmp/klippy.log
Enter fullscreen mode Exit fullscreen mode
  1. Enable klipper
sudo ln -srv /etc/sv/klipper /var/service
Enter fullscreen mode Exit fullscreen mode
  1. It be a good idea to reboot too.

After this plug in your printer if is not already, make sure you have your printer.cfg in your home dir, sudo sv restart klipper and you should be connected. I have an ender 3 with LCD enabled so I could confirm at this point that the LCD menu works. On to OctoPrint.


OctoPrint

All of the dependencies got installed in the Klipper install, so this is pretty simple.

  1. make the directory
cd ~
mkdir OctoPrint && cd OctoPrint
Enter fullscreen mode Exit fullscreen mode
  1. Setup Python3 venv
python3 -m venv venv
source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode
  1. Install Octoprint
./venv/bin/pip install pip --upgrade
./venv/bin/pip install octoprint
Enter fullscreen mode Exit fullscreen mode
  1. Create runsv service(runit) direcotry and file
sudo mkdir /etc/sv/octoprint
sudo touch /etc/sv/octoprint/run
sudo chmod +x /etc/sv/octoprint/run
Enter fullscreen mode Exit fullscreen mode
  1. Edit the file /etc/sv/octoprint/run
#!/bin/bash
export USER=pi
export HOME=/home/pi
groups="$(id -Gn "$USER" | tr ' ' ':')"

exec chpst -u "$USER:$groups" "$HOME"/OctoPrint/venv/bin/octoprint serve

Enter fullscreen mode Exit fullscreen mode
  1. Enable Octoprint
sudo ln -srv /etc/sv/octoprint /var/service
Enter fullscreen mode Exit fullscreen mode

Another restart might be good.

Once you open Octoprint in the browser you should install the OctoKlipper plugin.

By default the octoprint instance runs on port 5000. So something like localhost:5000 should get you there, or the ip of the machine with void.


Webcam

  1. Install some things
sudo xbps-install subversion libjpeg-turbo-devel ffmpeg 
cmake
Enter fullscreen mode Exit fullscreen mode
  1. Get the repo and build it
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
make
Enter fullscreen mode Exit fullscreen mode
  1. Test it
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
Enter fullscreen mode Exit fullscreen mode

Press Control-C to exit
You may have to add a device. in my case my laptop has a built in camera but I want to use the USB one, so I use(example)

./mjpg_streamer -i "./input_uvc.so -d /dev/video2" -o "./output_http.so -w ./www"
Enter fullscreen mode Exit fullscreen mode
The `-d /dev/video2` part is different.
You can this will give you a video feed on port `8080`.
Enter fullscreen mode Exit fullscreen mode
  1. Setup Octoprint

    In octoprint goto settings and webcam & timelapse section. In the "Stream URL" section put the http://ip:port/?action=stream, example http://192.168.0.24:8080/?action=stream.
    If you want Timelapse enter the same http://ip:port part but with /?action=snapshot at the end, example http://192.168.0.24:8080/?action=snapshot
    You should know have a video feed.

  2. Setting it up to autostart. first make the files

sudo mkdir /etc/sv/octocam
sudo touch /etc/sv/octocam/run
sudo chmod +x /etc/sv/octocam/run
Enter fullscreen mode Exit fullscreen mode
  1. Create a executable file that has the start command I had trouble getting this to work any other way I tried, you need to make a file, /home/pi/bin/octocam_run, like so
mkdir ~/bin
touch ~/bin/octocam_run
chmod +x ~/bin/octocam_run
Enter fullscreen mode Exit fullscreen mode

Next, put the following into the /home/pi/bin/octocam_run file

#!/bin/bash

MJPGSTREAMER_HOME=/home/pi/mjpg-streamer/mjpg-streamer-experimental
camera_options="-r 640x480 -f 10"

pushd $MJPGSTREAMER_HOME
LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so $camera_options -d /dev/video2"
popd

Enter fullscreen mode Exit fullscreen mode
  1. Add content to the /etc/sv/octocam/run file
#!/bin/bash
export USER=pi
export HOME=/home/pi
groups="$(id -Gn "$USER" | tr ' ' ':')"

exec chpst -u "$USER:$groups" /home/pi/bin/octocam_run

Enter fullscreen mode Exit fullscreen mode
  1. last add it to your services
sudo ln -sv /etc/sv/octocam /var/service
Enter fullscreen mode Exit fullscreen mode

If you have not, maybe do a reboot.

Please let me know if I have messed anything up if there is a better way to do this. And any errors your eyes sea please.

Sources

- Klipper Install
    - https://www.klipper3d.org/Installation.html
- Void Docs
    -https://docs.voidlinux.org/config/services/index.html
    - https://docs.voidlinux.org/config/services/user-services.html
- OcotPrint Help
    - https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspbian-or-raspberry-pi-os/2337
- And the install scripts from klipper, a few man pages here and there.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)