Problems with USB printer and hotplug script
Posted: Sun Aug 25, 2013 12:41 pm
I'm trying to run an HP LaserJet 1020 printer connected via USB to a TP-Link WDR-4300 v1.3 with Gargoyle 1.5.10 installed.
The router works perfectly in all aspects but I can't print via USB.
When I connect the printer to the usb port is detected by Gargoyle, and indeed in the web interface displays the message "HP LaserJet 1020 is connected via USB - You can connect to your printer on IP 192.168.1.1 via HP JetDirect Protocol". So far so good. Then I set the printer in Windows by following the tutorial and send a job to print... nothing happens. Reading here I find that this printer need to download their firmware every time is powered-on or else it wont work. So, following the blog instructions and other sources like this, this and this, I get to write the following script:
For the script to run, I downloaded the firmware (sihp1020.dl and put it in /usr/lib), then I installed usbutils package through opkg, and from here I donwloaded the usb_interface binary and then copied in /user/bin (I used it to check if the firmware is already in the printer or not).
Also, I added this to /etc/config/firewall
I rebooted the router, powered on the printer, send a print job and... nothing happends. It appears in the webinterface, but when I print it not work. The job is sent (in the router's log appears a connection and job received in port 9100) but nothing comes from the printer.
After much testing and error, I discovered that the script fails on the line 9 when is trying to check the existence of /dev/usb/lp0. If I use the sentence
if [-c $ DEVICE]
as the test condition it fails (wich is rare, because in theory lp0 is a character-device). I tried changing it by
if [ $(ls / dev/usb/lp0 | grep-c lp0) == 1 ]
but also fails (for unkwnon reasons). Then I directly eliminated the "if" and replaced directly by:
sleep 3
followed by
cat $FIRMWARE > $DEVICE
but also not work! Nothing happens, the firmware is not sent.
All the rest of the script is tested and it works.
The strangest thing of all is that if I write directly from the console:
cat $FIRMWARE > $DEVICE
and then invoke
sh /usr/lib/gargoyle/configure_printer.sh
(to set the webinterface and the p910d print server) the printer starts (you hear the sound that starts) and then prints normally!!
So.. what can be happening with the hotplug script? Can anyone give me some help?
Thanks in advance and sorry for my bad english (I'm from Argentina).
The router works perfectly in all aspects but I can't print via USB.
When I connect the printer to the usb port is detected by Gargoyle, and indeed in the web interface displays the message "HP LaserJet 1020 is connected via USB - You can connect to your printer on IP 192.168.1.1 via HP JetDirect Protocol". So far so good. Then I set the printer in Windows by following the tutorial and send a job to print... nothing happens. Reading here I find that this printer need to download their firmware every time is powered-on or else it wont work. So, following the blog instructions and other sources like this, this and this, I get to write the following script:
and save it as: /etc/hotplug.d/30-hplj1020 (in that directory I see also the files 10-usb, 20-modeswitch and 80-usb-printer).#!/bin/sh
DEVICE=/dev/usb/lp0
FIRMWARE=/usr/lib/sihp1020.dl
PROD_ID=3f0/2b17/100
if [ "$ACTION" == "add" ] && [ "$DEVTYPE" == "usb_interface" ] && [ "$PRODUCT" == "$PROD_ID" ]; then
for i in $(seq 10); do
if [ -c $DEVICE ]; then
if [ $(usb_printerid $DEVICE | grep -c FWVER) == 0 ]; then
cat $FIRMWARE > $DEVICE
exit
fi
else
sleep 3
fi
done
fi
For the script to run, I downloaded the firmware (sihp1020.dl and put it in /usr/lib), then I installed usbutils package through opkg, and from here I donwloaded the usb_interface binary and then copied in /user/bin (I used it to check if the firmware is already in the printer or not).
Also, I added this to /etc/config/firewall
to allow connections on port 9100.# Allow network attached printer
config 'rule'
option 'src' 'lan'
option 'proto' 'tcp'
option 'dest_port' '9100 '
option 'target' 'ACCEPT'
I rebooted the router, powered on the printer, send a print job and... nothing happends. It appears in the webinterface, but when I print it not work. The job is sent (in the router's log appears a connection and job received in port 9100) but nothing comes from the printer.
After much testing and error, I discovered that the script fails on the line 9 when is trying to check the existence of /dev/usb/lp0. If I use the sentence
if [-c $ DEVICE]
as the test condition it fails (wich is rare, because in theory lp0 is a character-device). I tried changing it by
if [ $(ls / dev/usb/lp0 | grep-c lp0) == 1 ]
but also fails (for unkwnon reasons). Then I directly eliminated the "if" and replaced directly by:
sleep 3
followed by
cat $FIRMWARE > $DEVICE
but also not work! Nothing happens, the firmware is not sent.
All the rest of the script is tested and it works.
The strangest thing of all is that if I write directly from the console:
cat $FIRMWARE > $DEVICE
and then invoke
sh /usr/lib/gargoyle/configure_printer.sh
(to set the webinterface and the p910d print server) the printer starts (you hear the sound that starts) and then prints normally!!
So.. what can be happening with the hotplug script? Can anyone give me some help?
Thanks in advance and sorry for my bad english (I'm from Argentina).