Mobile Bluetooth Printing, Linux Command Line Edition

The first step was to discover and pair the printer with my Linux box. There seem to be a number of different tools and methods for doing this. I found that the basic pairing process was easily accomplished using bluetoothctl. Though, it wasn't quite obvious where to go from there.

I made one leap forward when when I discovered that I could connect the rfcomm device to the printer, using something like this command:

sudo rfcomm connect DL58 00:14:01:03:5A:26

When I did this, the printer chirped to life and printed out these lines of text:

Wait a second, those are AT commands--I recognize them from my old modem days. I read this as follows: the printer was reporting that I had a serial connection to it and it was awaiting the proper set of AT commands.

I went back to the eBay seller: did they have these AT commands documented? Alas, they didn't. Well that's too bad.

I put the printer down for a couple days and tried again. This time I happened to run an lsof and found that a program, ModemManager, had the rfcomm device open. Wait a second: I was reading the above conversation all wrong. The system saw rfcomm device come on line and ModemManager sent it some AT commands to try to get it configured. The printer, being a printer, printed the commands.

I disabled ModemManager by running sudo systemctl disable ModemManager. I then rebootd the system and ran the following commands:

Because the printer follows one of the core principles of Linux (treat everything like a file), it's trivially to script. For example, I can enter the following to print a quippy statement:

(fortune -n 50 ; echo ; echo ; echo) > /dev/refcomm0

The -n keeps fortune from generating an especially long message, and the extra echo's serve to advance the paper.

Here's a slightly more realistic example: Shira's headaches are often tied to changes in barometric pressure. I created the script below to capture the current pressure in our area. I can then kick off the following command line:

The result is an old timey ticker tape of barometric pressure data. Here's one run:

I'm telling you, this Linux stuff is addictive. Could I have written the above code on Windows? Probably. Would it have taken me a matter of minutes, definitely not. I'm still not 100% sure I'll find a use for the DL58 printer attached to my Linux box, but I'm super impressed at how easy it is to leverage it.

1 comment:

Hi,thank you for nice how to. On your printer receipt I can see that there is time and date stamp and then pressure. I done everything it is working but on receipt show only pressure. No time and date. Can you help me setup date, time and pressure. Or maybe there is possibility to show temperature? Thank you in advance.