Thursday, March 08, 2007

Printing on Windows or Ubuntu with Bluetooth dongle and BT-Parallel adapter

I really like Linux. As well as I like Windows or MacOSX. Maybe I just like to try new things. But Linux sometimes can be a pain. I'm not a complete noob but neither I am an expert.

Today needed to configure Ubuntu 6.10 with a D-Link DBT-120 Bluetooth dongle to print to an old (but extremely reliable) HP Laserjet 4L using a Bluetooth to Parallel Bluetake BT-200 printer adapter. I already knew that it was not going to be a plug and play experience, since even in Windows it's not easy to make work this configuration.

On Windows, the problem comes in two parts: first, the BT200 printer adapter does not offers a plain Bluetooth Printing interface like other products, but offers a Serial Cable Replacement service. And the Windows native bluetooth drivers doesn't support that particular protocol (I've always wonder why Microsoft has always neglected a good BT support). In case you ever need to make a thing like that work, the trick consist on replacing the Windows drivers with the plain old Widcomm drivers, and create a Cable Replacement link to the printer adapter, not pairing the BT devices and adding manually your printer model and selecting the COM port assigned to the Cable Replacement link. Once you get the configuration correct printing is pretty reliable. You can find the indications on Bluetake's site.

When in comes to Linux Ubuntu 6.10, there are no specific instructions for that configuration so I hope to save someone a couple (or three, or four, or...) hours figuring what to do. The point is quite the same as on Windows: you have to create a virtual serial port that uses the BT Cable Replacement protocol to connect to the printer adapter and assign the serial port to the CUPS printer driver. First, you have to get your BT dongle working on Linux. Some instruction here but consider that on my configuration of Ubuntu the installation of bluez is not necessary since the kernel already has BT support, so instead of using

sudo /etc/init.d/bluez-utils restart

you must use

sudo /etc/init.d/bluetooth restart

and so on. I could not get to discover the adaptor using hidd but I could using

hcitool scan

Get the MAC address of the adapter with that command. Query the services provided by the adapter using

$sdptool search sp [your MAC address here, like 00:08:F4:23:03:60]
Inquiring ...
Searching for sp on 00:08:F4:23:03:60 ...
Service Name: Cable Replacement
Service RecHandle: 0x10000
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1

Note the service name and the channel number. Create the file /etc/bluetooth/rfcomm.conf

$sudo vim /etc/rfcomm.conf

and type this (replace your own MAC and Channel)

rfcomm0 {
bind yes;
device 00:08:F4:23:03:60;
channel 1;
comment "Impresora Serial";
}

Note the line rfcomm0: this will be the name of the serial port that will be created on /dev/rfcomm0. Start the serial port now using

$sudo rfcomm bind 0


Check the creation of the port with

$ls /dev/rfcomm0
/dev/rfcomm0

Now you have the serial connection configured. You can even send a file to the printer using a simple redirection, and the printer gets connected automatically:

$cp filename.txt > /dev/rfcomm0

You may need to manually send a form feed to the printer (or press the FF button) to get the paper off the printer. The lines on the hardcopy may be mixed and overwritten. This is ok since the document you have sent may not have correctly set the line feeds.

Next, you need to configure CUPS (printing services on Unix). Unfortunately, the serial printing option comes disabled on Ubuntu 6.10 by default. You need to set it on.

$sudo dpkg-reconfigure cupsys

The blue screen will ask for a MIME for printing jobs thing, just leave as it is. On the next screen you will see some options for printing protocols and devices. Select serial. Click OK. CUPS will be resetted and the serial option will be available.

Next, you need to setup the printer. I think the easiest way to do this is setup the printer on the wizard and then modify the URI line on the config file. Go to System-Administration-Printing, double-click on the New Printer icon and select Printer Type: CUPS (IPP) (you will notice that if you select Local Printer/Select by Port any real serial ports you have will appear, but not the rfcomm port). On the URI textbox just type "serial" and press Forward. Select you printer driver from the list. Press Forward, add details and press Apply.

The wizard does not allow us to specify a serial driver other than the ones detected by it because it appends a IPP:// protocol to the device URI specification, so we need now to configure this manually.

$ sudo vim /etc/cups/printers.conf

You will have something like:

# Printer configuration file for CUPS v1.2.4
# Written by cupsd on 2007-03-08 17:44

Info
Location
DeviceURI serial
State Idle
StateTime 1173397494
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy retry-job


Change the DeviceURI line to

DeviceURI serial:/dev/rfcomm0

Save the file and restart CUPS

$sudo /etc/init.d/cupsys restart

And that's it. Try printing something using OpenOffice.

I don't know right now what to do to automatically configure on system on restart. I'll post as soon as i can figure it down.

Some references:
http://www.spiration.co.uk/post/1307
https://help.ubuntu.com/community/BluetoothSetup?highlight=%28CategoryBluetooth%29
http://www.brennan.id.au/15-System_Printing.html
http://www.linuxquestions.org/questions/showthread.php?t=308086
http://ubuntuforums.org/showthread.php?t=30209
http://mhonarc.axis.se/dev-etrax/msg06630.html
For the installation on Windows
http://www.bluetake.com/FAQ_BT200.htm