Skip to content

Instantly share code, notes, and snippets.

@RyanEwen
Last active October 17, 2024 15:57
Show Gist options
  • Save RyanEwen/ae81fc48ad00397f1026915f0e6beed9 to your computer and use it in GitHub Desktop.
Save RyanEwen/ae81fc48ad00397f1026915f0e6beed9 to your computer and use it in GitHub Desktop.
Run Klipper + Moonraker + Mainsail + KlipperScreen on an Android device using Linux Deploy

Using Android to run Klipper, Moonraker, Mainsail/Fuidd, and KlipperScreen

This gist is no longer maintained. Please visit d4rk50ul1's repo instead
This gist is no longer maintained. Please visit d4rk50ul1's repo instead
This gist is no longer maintained. Please visit d4rk50ul1's repo instead

Consider everything below to be outdated

Requirements

Setup Instructions

  • Install Linux Deploy.

  • Install XServer XSDL.

  • Create a container within Linux Deploy using the following settings:

    • Bootstrap:
      • Distro: Debian (buster)
      • Installation type: Directory
        Note: You can choose File but make sure it's large enough as you can't resize it later and 2 GB is not enough.
      • Installation path: /data/local/debian
        Note: You can choose a different location but if it's within ${EXTERNALDATA} then SSH may fail to start.
      • User name: android
        Note: You can choose something else if you make sure to update the scripts in this gist accordingly.
    • Init:
      • Enable: yes
      • Init system: sysv
    • SSH:
      • Enable: yes
    • GUI:
      • Enable: yes
      • Graphics subsystem: X11
      • Desktop environment: XTerm
  • SSH into the container.

  • Install Git and KIAUH:

    sudo apt install git
    git clone https://github.com/th33xitus/kiauh.git
  • Install Klipper, Moonraker, Mainsail (or Fluidd), and KlipperScreen:

    kiauh/kiauh.sh

    Note: KlipperScreen in particular will take a very long time (tens of minutes).

  • Find your printer's serial device for use in Klipper's printer.cfg:
    It will likely be /dev/ttyACM0 or /dev/ttyUSB0. Check if either of those appear/disappear under /dev/ when plugging/unplugging your printer.

    If you cannot find your printer in /dev/, then you can install the Octo4a app which includes a custom implementation of the CH34x driver. You don't need to run OctoPrint within it, but you will need to run the Octo4a app. To do this:

    • Install Octo4a from https://github.com/feelfreelinux/octo4a/releases
    • Run Octo4a and let it install OctoPrint (optionally tap the Stop button once it's done installing).
    • Make sure Octo4a sees your printer (it will be listed with a checked-box next to it).
    • Install Termux from https://f-droid.org/en/packages/com.termux
    • Run Termux and find the serial device created by Octo4a:
      pkg install tsu
      sudo ls -al /data/data/com.octo4a/files/serialpipe
      You should see that /data/data/com.octo4a/files/serialpipe is a link to /dev/pts/0 or similar. Whatever it's linked to is the serial port you should use in printer.cfg. You can uninstall Termux after this as it's not needed for anything else.
  • Make the serial device accessible to Klipper:

    sudo chmod 777 /dev/ttyACM0
    # or 
    sudo chmod 777 /dev/ttyUSB0
    # or 
    sudo chmod 777 /dev/pts/0
  • Install the init and xterm scripts from this gist:

    sudo wget -O /etc/default/klipper https://gist.github.com/RyanEwen/ae81fc48ad00397f1026915f0e6beed9/raw/58f2834497b2733c03ca42c9bf41b2b3d79d9319/etc_default_klipper
    sudo wget -O /etc/init.d/klipper https://gist.github.com/RyanEwen/ae81fc48ad00397f1026915f0e6beed9/raw/58f2834497b2733c03ca42c9bf41b2b3d79d9319/etc_init.d_klipper
    sudo wget -O /etc/default/moonraker https://gist.github.com/RyanEwen/ae81fc48ad00397f1026915f0e6beed9/raw/58f2834497b2733c03ca42c9bf41b2b3d79d9319/etc_default_moonraker
    sudo wget -O /etc/init.d/moonraker https://gist.github.com/RyanEwen/ae81fc48ad00397f1026915f0e6beed9/raw/58f2834497b2733c03ca42c9bf41b2b3d79d9319/etc_init.d_moonraker
    sudo wget -O /usr/local/bin/xterm https://gist.github.com/RyanEwen/ae81fc48ad00397f1026915f0e6beed9/raw/58f2834497b2733c03ca42c9bf41b2b3d79d9319/usr_local_bin_xterm
    
    sudo chmod +x /etc/init.d/klipper 
    sudo chmod +x /etc/init.d/moonraker 
    sudo chmod +x /usr/local/bin/xterm
    
    sudo update-rc.d klipper defaults
    sudo update-rc.d moonraker defaults
  • Stop the Debian container.

  • Start XServer XSDL.

    • One time setup:
      • Tap 'Change Device Configuration'
      • Change Mouse Emulation Mode to Desktop, No Emulation
  • Start the Debian container.

  • KlipperScreen should appear in XServer XSDL and Mainsail and/or Fluidd should be accesible using your Android device's IP address in a browser.

Misc

You can start/stop Klipper and Moonraker manually by using the service command (eg: sudo service start klipper).
Logs can be found in /home/android/klipper_logs.

# Configuration for /etc/init.d/klipper
KLIPPY_USER=android
KLIPPY_CONFIG=/home/$KLIPPY_USER/klipper_config/printer.cfg
KLIPPY_LOG=/home/$KLIPPY_USER/klipper_logs/klippy.log
KLIPPY_SOCKET=/tmp/klippy_uds
KLIPPY_PRINTER=/tmp/printer
KLIPPY_EXEC=/home/$KLIPPY_USER/klippy-env/bin/python
KLIPPY_ARGS="/home/$KLIPPY_USER/klipper/klippy/klippy.py $KLIPPY_CONFIG -l $KLIPPY_LOG -a $KLIPPY_SOCKET"
# Configuration for /etc/init.d/moonraker
MOONRAKER_USER=android
MOONRAKER_CONFIG=/home/$MOONRAKER_USER/klipper_config/moonraker.conf
MOONRAKER_LOG=/home/$MOONRAKER_USER/klipper_logs/moonraker.log
MOONRAKER_SOCKET=/tmp/moonraker_uds
MOONRAKER_PRINTER=/tmp/printer
MOONRAKER_EXEC=/home/$MOONRAKER_USER/moonraker-env/bin/python
MOONRAKER_ARGS="/home/$MOONRAKER_USER/moonraker/moonraker/moonraker.py -c $MOONRAKER_CONFIG -l $MOONRAKER_LOG"
#!/bin/sh
# System startup script for Klipper 3d-printer host code
### BEGIN INIT INFO
# Provides: klipper
# Required-Start: $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Klipper daemon
# Description: Starts the Klipper daemon.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="klipper daemon"
NAME="klipper"
DEFAULTS_FILE=/etc/default/klipper
PIDFILE=/var/run/klipper.pid
. /lib/lsb/init-functions
# Read defaults file
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
case "$1" in
start) log_daemon_msg "Starting" $NAME
start-stop-daemon --start --quiet --exec $KLIPPY_EXEC \
--background --pidfile $PIDFILE --make-pidfile \
--chuid $KLIPPY_USER --user $KLIPPY_USER \
-- $KLIPPY_ARGS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping" $NAME
killproc -p $PIDFILE $KLIPPY_EXEC
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
log_end_msg $RETVAL
;;
restart) log_daemon_msg "Restarting" $NAME
$0 stop
$0 start
;;
reload|force-reload)
log_daemon_msg "Reloading configuration not supported" $NAME
log_end_msg 1
;;
status)
status_of_proc -p $PIDFILE $KLIPPY_EXEC $NAME && exit 0 || exit $?
;;
*) log_action_msg "Usage: /etc/init.d/klipper {start|stop|status|restart|reload|force-reload}"
exit 2
;;
esac
exit 0
#!/bin/sh
# System startup script for Moonraker API for Klipper
### BEGIN INIT INFO
# Provides: moonraker
# Required-Start: $local_fs $remote_fs klipper
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Moonraker daemon
# Description: Starts the Moonraker daemon.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="moonraker daemon"
NAME="moonraker"
DEFAULTS_FILE=/etc/default/moonraker
PIDFILE=/var/run/moonraker.pid
. /lib/lsb/init-functions
# Read defaults file
[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE
case "$1" in
start) log_daemon_msg "Starting" $NAME
start-stop-daemon --start --quiet --exec $MOONRAKER_EXEC \
--background --pidfile $PIDFILE --make-pidfile \
--chuid $MOONRAKER_USER --user $MOONRAKER_USER \
-- $MOONRAKER_ARGS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping" $NAME
killproc -p $PIDFILE $MOONRAKER_EXEC
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
log_end_msg $RETVAL
;;
restart) log_daemon_msg "Restarting" $NAME
$0 stop
$0 start
;;
reload|force-reload)
log_daemon_msg "Reloading configuration not supported" $NAME
log_end_msg 1
;;
status)
status_of_proc -p $PIDFILE $MOONRAKER_EXEC $NAME && exit 0 || exit $?
;;
*) log_action_msg "Usage: /etc/init.d/moonraker {start|stop|status|restart|reload|force-reload}"
exit 2
;;
esac
exit 0
#!/bin/bash
KLIPPERSCREEN_USER=android
KLIPPERSCREEN_CONFIG=/home/$KLIPPERSCREEN_USER/klipper_config/KlipperScreen.conf
KLIPPERSCREEN_LOG=/home/$KLIPPERSCREEN_USER/klipper_logs/KlipperScreen.log
/home/$KLIPPERSCREEN_USER/.KlipperScreen-env/bin/python /home/$KLIPPERSCREEN_USER/KlipperScreen/screen.py -c $KLIPPERSCREEN_CONFIG -l $KLIPPERSCREEN_LOG
@Saurabh251-cmd
Copy link

I have successfully installed debian,linux diploy on phone and can connect to xshell but issue is
WhatsApp Image 2022-12-06 at 8 36 24 PM
WhatsApp Image 2022-12-06 at 8 35 16 PM
its right?
Im having this issue even after starting services-
WhatsApp Image 2022-12-06 at 8 44 32 PM
Please guide me further to setup-

@Saurabh251-cmd
Copy link

After restarting phone this is issue-
WhatsApp Image 2022-12-06 at 9 00 37 PM
:(

@d4rk50ul1
Copy link

can you please share your configuration here:
image

@Saurabh251-cmd
Copy link

issue solved by reinstalling but still i will share u-

WhatsApp Image 2022-12-06 at 10 06 24 PM
![WhatsApp Image 2022-12-06 at 10 04 46 PM](https://user-images.githubusercontent.com/119947
WhatsApp Image 2022-12-06 at 10 04 57 PM
WhatsApp Image 2022-12-06 at 10 05 19 PM

991/205970392-941b719b-45cd-43e8-9488-86b1fa749d1b.jpeg)
WhatsApp Image 2022-12-06 at 10 04 50 PM

@Saurabh251-cmd
Copy link

WhatsApp Image 2022-12-06 at 10 04 46 PM

@d4rk50ul1
Copy link

@Saurabh251-cmd Is your Phone Rooted? Have you tried reinstalling Xdsl Server? not sure what can it be... @ZerGo0 any ideas?

@Saurabh251-cmd
Copy link

Saurabh251-cmd commented Dec 6, 2022

Ya it's rooted, successfully installed debian etc but now issue is -
IMG_20221207_004121

@d4rk50ul1
Copy link

Did you run all the ending scripts?
did you check on klippy.log and see if there is something not properly set up?
did you do printer.cfg config>?
just going over several considerations needed for this to work...

@Saurabh251-cmd
Copy link

image
how to fix this :<

@d4rk50ul1
Copy link

this is mostly configuration for your printer, now you must go to klipper page and seek for templates for your printer reference.

@Saurabh251-cmd
Copy link

Thank u,i will try btw can i use obico or something to stream live print ?

@QT7901
Copy link

QT7901 commented Feb 23, 2023

image
can anyone help me? termux shows my mcu as pts/15, I fixed it in printer.cfg but still can't connect

@d4rk50ul1
Copy link

Can you please share your printer.cfg MCU section?
Did you chmod your /dev/pts/15?

@QT7901
Copy link

QT7901 commented Feb 23, 2023

[mcu]
serial: /dev/pts/20
restart_method: command

this is what's in printer.cfg, every time I restart my machine and I check with termux the dev/pts/xxx changes again, now it's 20

@MAkSQWI
Copy link

MAkSQWI commented Mar 13, 2024

NEED HELP!
When I execute the copy command:

bash configuration_klipper_family.sh

I receive the following message:

Знімок екрана 2024-03-13 о 23 45 11

Can you Help me! I'm install and uninstall Klipper many times. No results...

@Bravelyan
Copy link

image can anyone help me? termux shows my mcu as pts/15, I fixed it in printer.cfg but still can't connect

how you fix it?

@Bravelyan
Copy link

Screenshot 2024-05-19 221706

i have same problem with this, can anyone tell me how to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment