Category Archives: linux

Connecting to Bluetooth serial devices on Gentoo LInux

This should’ve been easier, but in hindsight it isn’t too bad. The point-and-drool tools provided for managing Bluetooth (at least under KDE) fall flat on their face, but if you enable some supposedly deprecated options and rebuild BlueZ, you’ll get what you need.

I decided to try getting an HC-05 Bluetooth interface working with one of my 3D printers yesterday. bluedevil (the KDE package that manages Bluetooth) apparently knows nothing about RFCOMM devices (which emulate RS-232 connections over Bluetooth). I had gotten both Android and Windows 10 to talk to my printer over Bluetooth without much fuss: pair the device, fire up a suitable application, and connect.

The needed documentation to get RFCOMM devices working on recent Gentoo builds is a bit sparse, so this post aims to correct that.

First, BlueZ needs to be rebuilt with some more USE flags enabled:

echo net-wireless/bluez deprecated extra-tools readline | sudo tee /etc/portage/package.use/bluez && sudo emerge -1v bluez && sudo /etc/init.d/bluetooth restart

With your HC-05 at least powered up, you can retrieve its MAC address, which is needed for the following step:

hcitool scan

which returns something like this:

Scanning ...
        98:D3:32:10:F7:9C       HC-05

Next, RFCOMM needs to be configured and BlueZ restarted (wherever you see it below, substitute your device’s MAC address for the one used here):

cat <<EOF | sudo tee /etc/bluetooth/rfcomm.conf && sudo /etc/init.d/bluetooth restart
rfcomm {
  bind no;
  device 98:D3:32:10:F7:9C;
  channel 1;
}
EOF

Now we can pair the device to the computer:

sudo rfcomm connect hci0 98:D3:32:10:F7:9C 1

You should be prompted for the HC-05’s PIN; the default is 1234. (Note: while I’ve gotten this working under KDE, I never get prompted for the PIN when in a pure-CLI environment and the connection is refused.) Key it in, and you should get a notice that you’re now connected:

Connected /dev/rfcomm0 to 98:D3:32:10:F7:9C on channel 1
Press CTRL-C for hangup

Press Ctrl-C, then store the PIN for future reference:

for i in /var/lib/bluetooth/[0-9A-F]*; do echo 98:D3:32:10:F7:9C 1234 | sudo tee -a $i/pincodes; done

Create a boot script to bind /dev/rfcomm0:

cat <<EOF | sudo tee /etc/local.d/01-rfcomm-bind.start && sudo chmod +x /etc/local.d/01-rfcomm-bind.start
#!/usr/bin/env bash
rfcomm bind hci0 98:D3:32:10:F7:9C 1
EOF

Run rc-update and verify that both bluetooth and local are both being launched; in my case, both are in the default runlevel. If you reboot now, /dev/rfcomm0 should show up. Use something like minicom to connect, and if your HC-05 is plugged into a printer and the UART interface it’s using is active, you should at least see garbage coming across the line. The HC-05 defaults to 9600 bps, while your printer is probably at 115.2 kbps or faster. The only method I know of to set a different bitrate is to plug it in through an Arduino to bring up the AT-command interface, as described here. It doesn’t seem to support nonstandard speeds like 250 kbps and multiples thereof, and I even had trouble getting 230.4 kbps to work. 115.2 kbps has usually been fast enough to stream gcode without stalling; preprocessing your gcode with something like ArcWelder may help if your printer is running reasonably modern firmware.

Gentoo Linux, HPLIP, and the HP LaserJet 1320 don’t mix

If you try following the advice at the Gentoo Wiki, you would install HPLIP and use its hp-setup utility to add the printer to your system.  That way, however, lies madness…and printer communication errors.  I think this was the previous source of errors when I was using a JetDirect 175x between the computer and printer, but it’s not behaving any better with a direct USB connection.

Here’s what I ended up doing to get my printer working:

  1. emerge -C hplip && emerge foomatic-db-engine && /etc/init.d/cupsd restart
  2. Make sure USB printing support (CONFIG_USB_PRINTER) is enabled in the kernel…note that genkernel builds a kernel without it!
  3. Generate a PPD:
    foomatic-ppdfile -p `foomatic-searchprinter "HP LaserJet 1320"` >lj1320.ppd
  4. Go into the CUPS web interface and add the printer.  It should show up as a USB device.  When the option comes up to provide CUPS a PPD file, take it and use the file generated in the previous step.
  5. Once set up, double-check the printer default options to make sure the right paper size is selected.  (I think this method defaults to letter, but HPLIP used A4 as the default.  Either way, make sure it’s correct for what you’re using.)

Figuring all that out was three hours I won’t get back due to either buggy software (it wasn’t this tricky to get running on Kubuntu) or inadequate documentation.  At least now it’s written down to save others the aggravation.

Using Greyhole on Gentoo Linux just got easier

For a while, I was running Ubuntu Server instead of Gentoo on my home file server because I had some trouble figuring out how to get Greyhole running on it.

(Background: Greyhole is a redundant-storage subsystem that sits on top of Samba.  Basically, it allows you to combine multiple disks (not necessarily all the same size) into one pool of storage space.  If you have files you really don’t want to lose (like your wedding photos…but you should have backups!), you can tell it to maintain copies of those files on more than one drive…think of it as selective redundancy.  It’s been compared to the Drive Extender feature that used to be in Windows Home Server, but I don’t think Drive Extender provided redundant storage.)

Anyway, a desire to get my home server running Gentoo again prodded another attempt at getting Greyhole working on it.  A couple of weeks or so ago, I figured it out…but it was a manual process, and since it requires a loadable module to be built within the Samba source tree, it wasn’t going to be easily maintainable.

The solution to this?  Write an ebuild.  The peculiarities of getting Greyhole up and running made this a bit more tricky than usual, but I’ve done it:

https://github.com/salfter/portage/tree/master/net-fs/greyhole

This is part of my Portage overlay, which has a bunch of other ebuilds I’ve found useful over the years.  Installing Greyhole on Gentoo is now as simple as this:

  • add http://salfter.github.com/layman.xml to your overlays in /etc/layman/layman.cfg
  • layman -S && layman -a salfter to pull in the overlay
  • emerge greyhole to install
  • configure & enjoy!

One caveat: the Greyhole ebuild will currently only with with Samba 3.x.  The build process for Samba 4.x is a little bit different, and since I don’t have a Gentoo box running Samba 4 (it’s keyworded ~arch at this time), I don’t have a way to verify that it’ll work.  There are three FIXMEs that would need to be replaced to use Greyhole with Samba 4.x.)

Don’t cross the streams!

Surely a sign of TEOTWAWKI:

Bill Gates Inadvertently Shows Off Ubuntu on His Facebook Page

Screencapped, in case it goes down the memory hole:

bgates_ubuntu_fb_screencap

(Yes, the likely explanation is that he pulled a stock photo from somewhere, but you’d think he, of all people, would’ve spent a few minutes extra to find a stock photo with a Windows desktop.  Hell, he could’ve called someone in Microsoft’s PR department to either find an image or have one made on short order.)

Linux 3.17 is out, and some of my code is in it

It’s not the first time that happened…submitted a couple of drivers for a video-capture card we built at my previous job back around ’05 or ’06.

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/w1/slaves/w1_ds2406.c?id=refs/tags/v3.17

I submitted this a few months ago for my Raspberry Pi beer-fridge controller. I picked the parts and put it together without checking to see first if the necessary driver support was already in place…derp! Fortunately, it’s relatively easy to correct such deficiencies when you have source-code access to the whole system.