Wednesday, 25 January 2012

CUPS + HL-2140 (USB printer) + WZR-HP-G300NH + OpenWRT

Why running CUPS on the router?

I've had a small home server running Ubuntu to server the whole house, but it seems I'm the only one using it fully. I had my Brother HL-2140 connected to the server but since I've some spare room left in the router, why not run the print server on the router?

But why CUPS?

The other option I've is running non-spooling server, p910nd, but I believe I should make full use of the free space/memory on the router. If the router overloaded, I'll consider using p910nd later on.

What needs to be done to get CUPS running?

You need a capable router, WZR-HP-G300NH is one. It has 32MB flash ROM and 64MB RAM. I'm currently running OpenWrt Backfire 10.03.1-RC6 on it.

To install CUPS, just use LUCI to install the cups package.

How about getting the HL-2140 USB printer to work along?

There is nothing special, cups seems to have supported USB printer, so we shouldn't need to install the kmod-usb-printer package. It seems that the CUP's backend needs libusb, so, please install the libusb package.

just install the kmod-usb-printer package from LUCI, this will also install all the required packages such as kmod-usb-core, kmod-usb-ohci and kmod-usb2. If everything working, you'll see the following messages from dmesg or system log:

usblp0: USB Bidirectional printer dev 9 if 0 alt 0 proto 2 vid 0x04F9 pid 0x0033
usbcore: registered new interface driver usblp


There should be new device available: /dev/lp0


If everything works, you'll see your printer when you issue the following command:
root@OpenWrt:/mnt/share# /usr/lib/cups/backend/usb
DEBUG: list_devices
DEBUG: usb_find_busses=1
DEBUG: usb_find_devices=5
direct usb://Brother/HL-2140%20series?serial=F9J555425 "Brother HL-2140 series" "Brother HL-2140 series" "MFG:Brother;CMD:PJL,HBP;MDL:HL-2140 series;CLS:PRINTER;" ""



That is it?

Not so fast young man, there are few more things need to be done especially spooling. Since we've pretty much limited space, adding external USB storage is recommended. I've few USB sticks that I don't really use. So, I got myself a 4-port hub. Stick the 4GB USB stick, format it with ext4 and mount it. To get the USB storage working, I've installed kmod-usb-storage (I believe this will install few other packages too), kmod-fs-ext4 and e2fsprogs (to prepare the USB stick). Format the stick and mount it to /mnt/share and using LUCI, configure to make this mounted during bootup time.

The standard configuration file for CUPS has the USB pointing to /dev/usb/lp0 but OpenWRT has instead created /dev/lp0. So, edit /etc/cups/printers.conf and change that. Otherwise CUPS won't find the USB printer.

Here is my /etc/cups/cupsd.conf configuration file:
AccessLog syslog
ErrorLog syslog
LogLevel info
PageLog syslog
PreserveJobHistory No
PreserveJobFiles No
AutoPurgeJobs Yes
MaxJobs 25
MaxPrinterHistory 10
User root
Group root
RIPCache 512k
TempDir /mnt/share/cups
RequestRoot /mnt/share/cups
# Allow remote access
Port 631
Listen /var/run/cups/cups.sock
HostNameLookups Off
KeepAlive On
# Share local printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseRemoteProtocols
BrowseAddress @LOCAL
BrowseLocalProtocols CUPS
BrowseProtocols cups
< Location />
# Allow shared printing and remote administration...
Order allow,deny
Allow all
< /Location>
< Location /admin>
AuthType Basic
AuthClass System
# Allow remote administration...
Order allow,deny
Allow all
< /Location>
< Location /admin/conf>
AuthType Default
Require user @SYSTEM
# Allow remote access to the configuration files...
Order allow,deny
Allow all
< /Location>


NOTE: The code above won't allow me to have '< >' so, I put a space after the '<' .. So, edit and remove the space if you want to cut and paste my configuration. Yes, I'm allowing everyone to get access to CUPS configuration interface. You're free to edit it for sure. To add the printer, just go to http://your-router-ip-address:631 Go to administration, add printer, select the AppSocket/HP JetDirect option. Remember the output from /usr/lib/cups/backend/usb? Use the URI there and paste it into the "Connection" field. Example, for my printer, the URI returned by the backend command is: usb://Brother/HL-2140%20series?serial=F9J555425

Cut and paste the above into "Connection" field.

Somehow, we're not allowed by cups to have both User and Group to be the same, so to force the the backend to run as root, change the permission for /usr/lib/cups/backend/usb to 700.

Make sure cupsd running, so, fire it up in LUCI under System -> Startup, enable it and click start.

What else need to be done?

I had a problem when trying to print from my Mac, I'm getting an authentication error. Checking the syslog, there is this error: "Returning IPP client-error-not-authorized for Print-Job" and from my Mac, I'm getting "Authentication Required to Print" error. I didn't realised that I did not click on the "Share" option for the printer. So, if you're getting this error.. check if the printer has "Share This Printer" option ticked.

That is all .. have fun to get your printer + CUPS running on your router.

Thanks for the Openwrt wiki, somehow, my previous setup was working great until suddenly it won't print anything after I upgraded my router to the latest 10.03.01 backfire. So, please check for updated guide here:

http://wiki.openwrt.org/doc/howto/cups.server.

1 comment:

Sell Used Cell Phones said...
This comment has been removed by a blog administrator.

TOUCHTAB report, regenerate all ABAPs related to changed/modified structure

I was working on S4HANA OnPremis and tried to do an enhancement to BP's additional info structure by appending fields, but decided that ...