HP printer / scanner

This is just a quick writeup of what I have done so far to get an HP LaserJet M1522nf (printer / fax / scanner) to work. Currently this device is only used as a copier at the office, but many people asked about the scan button. My main goal is that users can simply press the scan button on the device in order to scan a document and save it to a Samba share.

After connecting the USB cable, Kubuntu automatically installs the printer in Cups. You can change the settings on http://localhost:631. To change the name of the printer (how it appears on the printers list), add a new printer with the same settings, and delete the old one. So now we have a working printer.

For scanning under X Window, try xsane. In my case it failed with an I/O error. The solution was this command:

hp-plugin -i

This installs any missing driver from HP. After that xsane works and we can do some scanning. So far so good.

For scanning on the commandline, use scanimage -L to get a list of devices, and use something like the following command to actually scan:

scanimage -d 'hpaio:/usb/HP_LaserJet_M1522nf_MFP?serial=00CNDT914GWT' --mode Color --resolution 300 > test.pnm

The argument after -d specifies the device found using scanimage -L.

Great! Next thing to do is monitoring the scan button. This however seems to be a major problem, because nobody appears to have implemented it yet. Even after more than 5 years, HP appearently has serious trouble supporting this simple scan button in their HPLIP library. Fortunately, there is another way. If you press the scan button, a message appears on the LCD: "Waiting for PC",

and after a few seconds a timeout occurs because the PC is not responding, after which the printer returns to its ready state.

On some HP printers you can read out the LCD, using the SNMP protocol. So indirectly you can tell whether or not the scan button has been pressed. The only thing to do is hookup the HP device to the network and give it a static (fixed) IP address. Here are some useful commands:

snmpwalk -v 1 -c public <ip_address_of_scanner>
scli <ip_address_of_scanner> -c "show printer display"
scli <ip_address_of_scanner> -c "show printer lights"

The snmpwalk command is part of the snmp package and you can find the scli command in the scli package.

However, the M1522nf does fully support SNMP; you cannot read out the LCD using SNMP on this thing. It does not support Telnet either, and there is no PJL command you can send to the JetDirect port (9100) to query the LCD display. The only way to do that using the web interface, so we use wget to do that every 5 seconds. Here the script I have come up with:


while [ 1 ]
   MSG="`wget -q -O - \
      '' | \
      grep -A2 'itemLargeFont' | tail -1 | sed -r 's/(&nbsp;| |\t)+/ /g' | \
      sed 's/<[^>]*>//g'`"
   if echo "$MSG" | grep -q 'Waiting for PC'
      echo "Scanning"
      scanimage -d hpaio:/usb/HP_LaserJet_M1522nf_MFP?serial=00CNDT914GWT \
         --mode Color --resolution 300 | cjpeg -optimize -quality 85 > \
         /share/Scanner/`date '+%Y-%m-%d-%H-%M-%S'`.jpg
      echo "Idle"
   sleep 5

In this case is the IP address of the printer and /share/Scanner is a directory on our NFS / Samba server. Now if someone presses the scan button, the scanner starts and the resulting image is converted from PNM to JPEG, and saved under a name like 2010-11-16-12:34:56.jpg.

Mission accomplished ;-)