Thursday, September 17, 2009

Linksys NSLU2 OpenWrt Sharing Multiple USB Printers

Most of the information required to share USB printers with OpenWrt is available here. I am just going to document a few details not covered in that document.
  • I had to write my own hotplug script, /etc/hotplug.d/usb/20-usb-printers, for giving the printers fixed symbolic links.

    #!/bin/sh
    
    create_link()
    {
     SYS_DEVDIR=/sys"$DEVPATH"/usb
     LP=`ls $SYS_DEVDIR`
     if [ ! -d "$SYS_DEVDIR/$LP" ]; then
      exit 
     fi
     REAL_DEV=/dev/`basename "$SYS_DEVDIR/$LP"`
     rm -f "$1"
     ln -s "$REAL_DEV" "$1"
    }
    
    process_action()
    {
     case "$ACTION" in
      remove)
       rm -f "$1"
       ;;
      add)
       create_link "$1"
       ;;
     esac
    }
    
    case "$PRODUCT" in
    
     "4b8/5/100") # EPSON C80
      process_action "/dev/inkjet"
      ;;
    
     "4f9/28/100") # BROTHER HL-2040
      process_action "/dev/laser"
      ;;
    
    esac
    

  • In addition, I created an init script, /etc/init.d/usbprinters, to make sure the links are also created when coldplugging the printers. Run /etc/init.d/usbprinters enable once after creating the script.

    #!/bin/sh /etc/rc.common
    
    START=39
    start() {
     [ -d /proc/bus/usb ] && {
      /sbin/udevtrigger --subsystem-match=usb --attr-match=bInterfaceClass=*7*
     }  
    }
    

  • Using these fixed symbolic links, /etc/config/p910nd now always exposes each printer on the same port:

    config p910nd
     option device        /dev/laser
     option port          0
     option bidirectional 1
     option enabled       1
    
    config p910nd
     option device        /dev/inkjet
     option port          1
     option bidirectional 1
     option enabled       1
    

  • I could not get avahi-daemon to work for advertising the printers via Zeroconf. Instead, I am using the no longer supported howl-mdnsresponder package (version 1.0.0-1). My /etc/mDNSResponder.conf looks like this.

    "Brother HL-2040 series" _pdl-datastream._tcp local. 9100 "txtvers=1" "note=Office" "product=(HL-2040 series)"
    "Epson Stylus C80"  _pdl-datastream._tcp local. 9101 "txtvers=1" "note=Office" "product=(Epson Stylus C80)"
    

    The idea is to use the product name that matches the product key in the PPD file on the client so that the client automatically suggests the right driver.

  • I manually downloaded and installed recent versions of ink and libinklevel from this repository, and now ink works with my Epson Stylus C80! I am using this script to see the ink levels as a bar chart in X-Wrt > Status > USB.

1 comment:

Apple Oracle said...

That's a handy script! Thanks!