Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ender 3 Pro | comm.py / serialposix.py Permission Errors | dietpi (debian 11 based) #5246

Closed
eyduh opened this issue Feb 8, 2022 · 2 comments

Comments

@eyduh
Copy link

eyduh commented Feb 8, 2022

Heye,

I'm having some trouble getting octoprint to talk to klipper/printer.

Logs

klippy.log seems fine, it is most likely an octoprint issue.
klippy.log

Context:

I used the install-debian.sh script as I want to run DietPi instead of OctoPrint. After some initial troubleshooting I noticed that the path for the usb tty ( /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 ) was owned by root:root which prevented klipper from talking to it due to permission issues, however, it was symlinked by default to /dev/ttyUSB0 so I commented the relevant line in the config and changed it to serial: /dev/ttyUSB0 which is owned by dietpi:dietpi and now klipper talks to the printer and the LCD on the printer shows the klipper interface instead of just blank.

Moving on from there I tried to get octoprint to talk to the printer but it keeps giving me trouble, saying "permission denied" to any attempts. I've checked permissions of various paths and the groups of the users involved (octoprint & dietpi) as detailed below. Not sure what to try next.

(I also left the BLTouch part commented despite using a BLTouch. I recommented this section because klippy logs told me I needed to add the z offset to the config, but, since the serial connection to the printer errored due to this part of the config missing, the LCD screen on the printer would stay blank and thus there was no way to get the z offset. I wasn't sure if I could use the z offset from before when running marlin so I decided to leave problem for future me and get everything else set up first.)

Looking through journalctl it seems that the problem relates to python and ports, but I'm no python expert so not sure where to go from here.

Detailed info

Systeminfo:

$ neofetch
       _,met$$$$$gg.          dietpi@dietprints0 
    ,g$$$$$$$$$$$$$$$P.       ----------------- 
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 11 (bullseye) aarch64 
 ,$$P'              `$$$.     Host: Raspberry Pi 4 Model B Rev 1.1 
',$$P       ,ggs.     `$$b:   Kernel: 5.10.92-v8+ 
`d$$'     ,$P"'   .    $$$    Uptime: 39 mins 
 $$P      d$'     ,    $$P    Packages: 582 (dpkg) 
 $$:      $$.   -    ,d$$'    Shell: bash 5.1.4 
 $$;      Y$b._   _,d$P'      Terminal: /dev/pts/1 
 Y$$.    `.`"Y$$$$P"'         CPU: BCM2835 (4) @ 1.500GHz 
 `$$b      "-.__              Memory: 181MiB / 889MiB 
  `Y$$
   `Y$$.                                              
     `$$b.                                            
       `Y$$b.
          `"Y$b._
              `"""

I changed the relevant settings in the octoprint webinterface to add /tmp/printer but it keeps getting permission denied on all baud rates.

Octoprint terminal on trying to connect to /tmp/printer:

Changing monitoring state from "Offline" to "Detecting serial connection"
Performing autodetection with 7 port/baudrate candidates: /tmp/printer@115200, /tmp/printer@250000, /tmp/printer@230400, /tmp/printer@57600, /tmp/printer@38400, /tmp/printer@19200, /tmp/printer@9600
Trying port /tmp/printer, baudrate 115200
Connecting to port /tmp/printer, baudrate 115200
Unexpected error while connecting to serial port /tmp/printer, baudrate 115200 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 115200, skipping
Trying port /tmp/printer, baudrate 250000
Connecting to port /tmp/printer, baudrate 250000
Unexpected error while connecting to serial port /tmp/printer, baudrate 250000 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 250000, skipping
Trying port /tmp/printer, baudrate 230400
Connecting to port /tmp/printer, baudrate 230400
Unexpected error while connecting to serial port /tmp/printer, baudrate 230400 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 230400, skipping
Trying port /tmp/printer, baudrate 57600
Connecting to port /tmp/printer, baudrate 57600
Unexpected error while connecting to serial port /tmp/printer, baudrate 57600 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 57600, skipping
Trying port /tmp/printer, baudrate 38400
Connecting to port /tmp/printer, baudrate 38400
Unexpected error while connecting to serial port /tmp/printer, baudrate 38400 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 38400, skipping
Trying port /tmp/printer, baudrate 19200
Connecting to port /tmp/printer, baudrate 19200
Unexpected error while connecting to serial port /tmp/printer, baudrate 19200 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 19200, skipping
Trying port /tmp/printer, baudrate 9600
Connecting to port /tmp/printer, baudrate 9600
Unexpected error while connecting to serial port /tmp/printer, baudrate 9600 from hook default: SerialException: '[Errno 13] could not open port /tmp/printer: [Errno 13] Permission denied: '/tmp/printer'' @ comm.py:_open_serial:3775
Could not open port /tmp/printer, baudrate 9600, skipping
Changing monitoring state from "Detecting serial connection" to "Error"
Changing monitoring state from "Error" to "Offline after error"

Additional info on /tmp/printer

$ stat /tmp/printer
  File: /tmp/printer -> /dev/pts/0
  Size: 10              Blocks: 0          IO Block: 4096   symbolic link
Device: 1ch/28d Inode: 125         Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/  dietpi)   Gid: ( 1000/  dietpi)
Access: 2022-02-08 13:57:19.134294295 +0100
Modify: 2022-02-08 13:57:19.134294295 +0100
Change: 2022-02-08 13:57:19.134294295 +0100
 Birth: -
$ stat /dev/pts/0
  File: /dev/pts/0
  Size: 0               Blocks: 0          IO Block: 1024   character special file
Device: 14h/20d Inode: 3           Links: 1     Device type: 88,0
Access: (0660/crw-rw----)  Uid: ( 1000/  dietpi)   Gid: (    5/     tty)
Access: 2022-02-08 13:57:19.134294295 +0100
Modify: 2022-02-08 13:57:19.134294295 +0100
Change: 2022-02-08 13:57:19.134294295 +0100
 Birth: -

Since

Octoprint terminal output when trying to connect to /dev/ttyUSB0:

Changing monitoring state from "Offline" to "Detecting serial connection"
Performing autodetection with 7 port/baudrate candidates: /dev/ttyUSB0@115200, /dev/ttyUSB0@250000, /dev/ttyUSB0@230400, /dev/ttyUSB0@57600, /dev/ttyUSB0@38400, /dev/ttyUSB0@19200, /dev/ttyUSB0@9600
Trying port /dev/ttyUSB0, baudrate 115200
Connecting to port /dev/ttyUSB0, baudrate 115200
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 115200 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 115200, skipping
Trying port /dev/ttyUSB0, baudrate 250000
Connecting to port /dev/ttyUSB0, baudrate 250000
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 250000 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 250000, skipping
Trying port /dev/ttyUSB0, baudrate 230400
Connecting to port /dev/ttyUSB0, baudrate 230400
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 230400 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 230400, skipping
Trying port /dev/ttyUSB0, baudrate 57600
Connecting to port /dev/ttyUSB0, baudrate 57600
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 57600 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 57600, skipping
Trying port /dev/ttyUSB0, baudrate 38400
Connecting to port /dev/ttyUSB0, baudrate 38400
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 38400 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 38400, skipping
Trying port /dev/ttyUSB0, baudrate 19200
Connecting to port /dev/ttyUSB0, baudrate 19200
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 19200 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 19200, skipping
Trying port /dev/ttyUSB0, baudrate 9600
Connecting to port /dev/ttyUSB0, baudrate 9600
Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 9600 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Could not open port /dev/ttyUSB0, baudrate 9600, skipping
Changing monitoring state from "Detecting serial connection" to "Error"
Changing monitoring state from "Error" to "Offline after error"

Additional info on /dev/ttyUSB0:
(As you can see the path by id is symlinked to ttyUSB0)

$ stat /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 
  File: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 -> ../../ttyUSB0
  Size: 13              Blocks: 0          IO Block: 4096   symbolic link
Device: 5h/5d   Inode: 388         Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-02-08 13:49:34.959999997 +0100
Modify: 2022-02-08 13:49:31.875999999 +0100
Change: 2022-02-08 13:49:31.875999999 +0100
 Birth: -
$ stat /dev/ttyUSB0
  File: /dev/ttyUSB0
  Size: 0               Blocks: 0          IO Block: 4096   character special file
Device: 5h/5d   Inode: 241         Links: 1     Device type: bc,0
Access: (0660/crw-rw----)  Uid: ( 1000/  dietpi)   Gid: ( 1000/  dietpi)
Access: 2022-02-08 14:15:44.875999999 +0100
Modify: 2022-02-08 14:15:44.875999999 +0100
Change: 2022-02-08 13:55:14.534294369 +0100
 Birth: -

octoprint is running with the user octoprint, klipper is running with the user dietpi:

$ groups octoprint
octoprint : octoprint tty dialout video dietpi
$ groups dietpi
dietpi : dietpi tty octoprint

And lastly, relevant systemlogs:

Feb 08 14:23:07 dietprints0 octoprint[1461]: 2022-02-08 14:23:07,769 - octoprint.util.comm - INFO - Serial detection: Could not open port /dev/ttyUSB0, baudrate 19200, skipping
Feb 08 14:23:07 dietprints0 octoprint[1461]: 2022-02-08 14:23:07,770 - octoprint.util.comm - INFO - Serial detection: Trying port /dev/ttyUSB0, baudrate 9600
Feb 08 14:23:07 dietprints0 octoprint[1461]: 2022-02-08 14:23:07,771 - octoprint.util.comm - INFO - Connecting to port /dev/ttyUSB0, baudrate 9600
Feb 08 14:23:07 dietprints0 octoprint[1461]: 2022-02-08 14:23:07,774 - octoprint.util.comm - ERROR - Unexpected error while connecting to serial port /dev/ttyUSB0, baudrate 9600 from hook default: SerialException: '[Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'' @ comm.py:_open_serial:3775
Feb 08 14:23:07 dietprints0 octoprint[1461]: Traceback (most recent call last):
Feb 08 14:23:07 dietprints0 octoprint[1461]:   File "/mnt/dietpi_userdata/octoprint/.local/lib/python3.9/site-packages/serial/serialposix.py", line 322, in open
Feb 08 14:23:07 dietprints0 octoprint[1461]:     self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
Feb 08 14:23:07 dietprints0 octoprint[1461]: PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'
Feb 08 14:23:07 dietprints0 octoprint[1461]: During handling of the above exception, another exception occurred:
Feb 08 14:23:07 dietprints0 octoprint[1461]: Traceback (most recent call last):
Feb 08 14:23:07 dietprints0 octoprint[1461]:   File "/mnt/dietpi_userdata/octoprint/.local/lib/python3.9/site-packages/octoprint/util/comm.py", line 3775, in _open_serial
Feb 08 14:23:07 dietprints0 octoprint[1461]:     serial_obj = factory(
Feb 08 14:23:07 dietprints0 octoprint[1461]:   File "/mnt/dietpi_userdata/octoprint/.local/lib/python3.9/site-packages/octoprint/util/comm.py", line 3740, in default
Feb 08 14:23:07 dietprints0 octoprint[1461]:     serial_obj.open()
Feb 08 14:23:07 dietprints0 octoprint[1461]:   File "/mnt/dietpi_userdata/octoprint/.local/lib/python3.9/site-packages/serial/serialposix.py", line 325, in open
Feb 08 14:23:07 dietprints0 octoprint[1461]:     raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
Feb 08 14:23:07 dietprints0 octoprint[1461]: serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'


This repeats for every baudrate and is the same for both /dev/ttyUSB0 and /tmp/printer.

When I was running the stock Marlin+bltouch from Creality I could connect octoprint and the printer thus reporting this here and not on octoprint git.

edit: added the dev path for the usb serial. In doing this I noticed the path mentions port0 at the end, but in the python part of the logs port 3775 is mentioned - could this be the issue?

@eyduh
Copy link
Author

eyduh commented Feb 9, 2022

Solution

I got the /tmp/printer step to work by following the symlink to its source and adding that to OctoPrint instead.


Details

While troubleshooting I noticed that /tmp/printer was a symlink to the actual virtual port that Klipper setup:

In the printer.cfg the serial port of the printer is listed by id, DietPi adds this as /dev/ttyUSBn depending on what you have plugged in.

Then klipper set's up the virtual serial port /dev/pts/n which is symlinked to /tmp/printer.

By following the OctoPrint steps but using the actual /dev/pts/n location rather than the symlink it worked fine.

It should work with the symlink though, despite octoprint & klipper running under different users, as the relevant users and groups are set up:

$ stat /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
  File: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 -> ../../ttyUSB0
  Size: 13              Blocks: 0          IO Block: 4096   symbolic link
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)

$ stat /dev/ttyUSB0
  File: /dev/ttyUSB0
  Size: 0               Blocks: 0          IO Block: 4096   character special file
Access: (0660/crw-rw----)  Uid: (    0/    root)   Gid: (   20/ dialout)


$ stat /tmp/printer 
  File: /tmp/printer -> /dev/pts/0
  Size: 10              Blocks: 0          IO Block: 4096   symbolic link
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/  dietpi)   Gid: ( 1000/  dietpi)

$ stat /dev/pts/0
  File: /dev/pts/0
  Size: 0               Blocks: 0          IO Block: 1024   character special file
Device: 14h/20d Inode: 3           Links: 1     Device type: 88,0
Access: (0660/crw-rw----)  Uid: ( 1000/  dietpi)   Gid: (    5/     tty)

And the users:

$ id octoprint
uid=997(octoprint) gid=995(octoprint) groups=995(octoprint),5(tty),20(dialout),44(video),1000(dietpi)
$ id dietpi
uid=1000(dietpi) gid=1000(dietpi) groups=1000(dietpi),5(tty),20(dialout),44(video),995(octoprint)

$ groups octoprint
octoprint : octoprint tty dialout video dietpi
$ groups dietpi 
dietpi : dietpi tty dialout video octoprint

Seeing as symlinks under GNU/Linux have 777 permissions, and the files they are pointing to have 660 (rw for users and group) I really don't understand what the problem is.

On a different note, it seems that Klipper can use both the symlink /dev/ttyUSBn and the actual location by id in the printer.cfg file.

Maybe it would be good to troubleshoot the install-debian.sh script to figure out why octoprint can't connect to /tmp/printer despite it being a symlink to /dev/pts/0 and all the user/group permissions are correct.


tl;dr:
If OctoPrint can't connect to /tmp/printer try adding the device that it is pointing to.

@eyduh eyduh closed this as completed Feb 9, 2022
@Sineos
Copy link
Collaborator

Sineos commented Feb 9, 2022

Most likely this issue:
#1902 (comment)

@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants