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

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

Open
ihrapsa opened this issue Jun 18, 2021 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@ihrapsa
Copy link
Owner

ihrapsa commented Jun 18, 2021

  • 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 ihrapsa added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 18, 2021
@ihrapsa ihrapsa self-assigned this Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant