KlipperWrt icon indicating copy to clipboard operation
KlipperWrt copied to clipboard

[guide] Add instructions to create hotplug rules for persistent tty ports

Open ihrapsa opened this issue 3 years ago • 0 comments

  • opkg update && opkg install usbutils

  • use lsusb - find your mainboard ID: idVendor:idProduct

  • do grep idVendor/idProduct /sys/bus/usb/devices/*/uevent - replace idVendor and idProduct accordingly

  • note the values of PRODUCT: something like 1a86/7523/264 (these are specific to my mainboard type)

  • do the command block below that will create a hotplug rule (edit the file after: /etc/hotplug.d/usb/22-tty-symlink after running the below command) and replace PRODID to the values of PRODUCT= from the grep command above. Change SYMLINK name to your likings just don't use spaces.

  • plug/unplug your printer while on and check if symlink is created inside /dev with ls -l /dev. your SYMLINK name should point to a serial port something like SYMLINK -> /dev/ttyUSB0

  • inside printer.cfg replace the serial path under [mcu] to /dev/SYMLINK where SYMLINK should be your chosen name OR ttyPrinter (as it is by default)

cat << "EOF" > /etc/hotplug.d/usb/22-tty-symlink
# Description: Action executed on boot (bind) and with the system on the fly
PRODID="1a86/7523/264" #change here according to "PRODUCT=" from grep command 
SYMLINK="ttyPrinter" #you can change this to whatever you want just don't use spaces. Use this inside printer.cfg as serial port path
if [ "${ACTION}" = "bind" ] ; then
  case "${PRODUCT}" in
    ${PRODID}) # mainboard product id prefix
      DEVICE_TTY="$(ls /sys/${DEVPATH}/tty*/tty/)"
      # Mainboard connected to USB1 slot
      if [ "${DEVICENAME}" = "1-1.4:1.0" ] ; then
        ln -s /dev/${DEVICE_TTY} /dev/${SYMLINK}
        logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to /dev/${SYMLINK} created"

      # Mainboard connected to USB2 slot
      elif [ "${DEVICENAME}" = "1-1.2:1.0" ] ; then
        ln -s /dev/${DEVICE_TTY} /dev/${SYMLINK}
        logger -t hotplug "Symlink from /dev/${DEVICE_TTY} to /dev/${SYMLINK} created"
      fi
    ;;
  esac
fi
# Action to remove the symlinks
if [ "${ACTION}" = "remove" ]  ; then
  case "${PRODUCT}" in
    ${PRODID})  #mainboard product id prefix
     # Mainboard connected to USB1 slot
      if [ "${DEVICENAME}" = "1-1.4:1.0" ] ; then
        rm /dev/${SYMLINK}
        logger -t hotplug "Symlink /dev/${SYMLINK} removed"

      # Mainboard connected to USB2 slot
      elif [ "${DEVICENAME}" = "1-1.2:1.0" ] ; then
        rm /dev/${SYMLINK}
        logger -t hotplug "Symlink /dev/${SYMLINK} removed"
      fi
    ;;
  esac
fi
EOF

ihrapsa avatar Jun 18 '21 17:06 ihrapsa