Klipper on android

I’m trying to install Klipper on my LG V20 running LOS 18.1 (AOSP 11) and a 3.18 kernel compiled with the ch341 driver. I’ve seen multiple instances of people having installed Klipper on their Android device in a chrooted Linux: 1, 2. I’ve been trying to do that for the past few days, but with little success even though, on the exact same setup, Octoprint was running for over a month with little to no Issues. The main problem I’m facing is the printer not showing up in /dev/serial/ , It only shows up in /dev/ttyUSB[0-9] and /dev/bus/usb/001/00[^1] and when I point the serial: flag in printer.cfg to it I get errors in the klippy.log like ‘can’t open /dev/ttyUSB0’. I tried changing the permissions to 777, doesn’t work. I also tried installing Klipper in a VM on my main PC, it works and can communicate with the printer. My best guess is that I don’t have proper kernel serial driver support, that would make this question a bit off-topic, but I’ve asked on multiple places and still haven’t figured it out. TLDR; Printer doesn’t show up in /dev/serial on Android, how do I fix it so it does?
Fluidd error:

mcu 'mcu': Unable to connect
Once the underlying issue is corrected, use the
"FIRMWARE_RESTART" command to reset the firmware, reload the
config, and restart the host software.
Error configuring printer

Important tail of klippy.log:

mcu 'mcu': Starting serial connect
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
webhooks client 488878322544: New connection
webhooks client 488878322544: Client info {'program': 'Moonraker', 'version': 'v0.7.1-376-g34f607c'}
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'
mcu 'mcu': Unable to open serial port: [Errno 2] could not open port /dev/bus/usb/001/002: [Errno 2] No such file or directory: '/dev/bus/usb/001/002'

…same with /dev/ttyUSB0.
Important output of lsusb:

Bus 001 Device 004: ID 1a86:7523 QinHeng Electronics CH340 serial converter
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x1a86 QinHeng Electronics
  idProduct          0x7523 CH340 serial converter
  bcdDevice            2.64
  iManufacturer           0
  iProduct                2 USB Serial
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0027
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               98mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      1
      bInterfaceProtocol      2
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               1
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)

Edit, forgot the output of dmesg, it recognizes the printer and attaches the ch341-uart converter to it (just search for ‘ch341’): http://sprunge.us/HfUEAe (too long of a message, and I’m getting an error when uploading a txt/zip)

I hope I’m not too off-topic and that anyone who has any ideas will chime in.

I don’t fully understand the situation here. You seem to say that the printer appears as /dev/ttyUSB0, but you say the error message is the same (No such file or directory). Is this really true, or is this part in the log actually different? If yes, can you please post that?

I could imagine that SELinux gets in the way on Android. Have you tried switching it into permissive mode (run setenforce 0 as root on command line)? This of course won’t help if the dev node does not even appear. If that is the case despite dmesg tells you it attaches the device as ttyUSB0, I guess there is something weird wrong with udev…

You seem to say that the printer appears as /dev/ttyUSB0, but you say the error message is the same ( No such file or directory )

Yes, exactly. The file is there and can be operated on with Octoprint. The permissions are set to 777 and I’m in both the ‘tty’ and the ‘dialout’ group. I’ll try adding my self to all groups, because from what I’ve seen there is a lot of groups and I haven’t gone through all of them, maybe the issue lies there.

SELinux

I’m not sure, but I think when I compiled the kernel I put selinux to be permissive in the zip script. Either way, I’ll try it.

Udev

During my research I also stumbled upon this thought but unfortunately I have very minimal experience with udev rules, so I can’t do much about it myself.

I still think the biggest issue is the printer not showing up in /dev/serial. I don’t know if Android handles serial devices differently from normal Linux, it could be the problem, but I’m skeptical of that. Thank you for the answer, tomorrow I’ll install Klipper again and try some of the proposed ideas.

I tried adding myself to all groups and setting ‘setenforce’ to 0. Unfortunately it didn’t help. I still can’t see my printer in /dev/serial. I also asked on StackExchange and the one answer also mentioned udev rules. I guess this is the main culprit for now.

What I still don’t understand: If /dev/ttyUSB0 exists, why can’t you use it? Is it a symlink pointing to a non-existing device node in /dev/serial? On my Linux system it is the other way round: /dev/serial only contains symlinks to /dev/ttyUSB0 etc. The only advantage of using /dev/serial is that the name stays stable and independent of e.g. the order you plug in your devices. Still if you know /dev/ttyUSB0 is the correct device, you should be able to use it. If you are not, the symlink in /dev/serial won’t help either.

If /dev/ttyUSB0 exists, why can’t you use it?

Of course I tried using it. I answered that in the OP and clarified it in my second post. Klipper cannot open the file and it complains that there is ‘no such file or directory’, even when there clearly is.
I believe that there is something wrong deeper inside and that’s why the symlink in /dev/serial isn’t created. The problem isn’t based around the printer not showing in /dev/serial/, rather I think that is a mere symptom of a bigger issue. And there shouldn’t be any problem with the printer and it’s installation as it just werks on my main machine.

I am sorry. I had to be sure I understood you correctly, since it sounds so weird :slight_smile:

If /dev/ttyUSB0 exists and is not a symlink pointing into nirvana, the error message does not make any sense. Can you try opening the device with a different program like minicom or just cat?