MQTT Republishing Itch

So, I had an itch. A variety of data coming in from a variety of sources, all over different protocols and methods, with different names, heirarchies, and paths. For a while I’d been pushing the data into MySQL, but this seemed a bit of a hack, and it still didn’t really cure the problem as it was more of a historical record than an attempt at mapping between the source and the destination, as it were.

I’d been fiddling with MQTT for a while, and had started publishing data over it via my personal broker. And then I read Roberts post over at about republishing it in a logical way.

So simple! So, I wrote a republisher. It’s very simple, and it scratches my itch (and hopefully Roberts too). Data comes in via whatever naming scheme or topic you like, and it gets republished in whatever fashion you want. The map is maintained in map.csv, and items are separated by commas. The MQTT spec doesn’t reserve any characters for the topic name, so I’ve used a comma out of CSV convenience.

The code is over at

Making XBMC work on Mint 12, with HDMI Audio Passthrough and LIRC

I’ve got a Dell Optiplex 755 hooked up to my Yamaha amp and surround system, and it was about time XBMC was installed on it. It uses a low profile Nvidia GeForce 8400GS for VDPAU acceleration and HDMI audio. These are some rough notes I took whilst setting it up.

Follow this guide to install XBMC on Mint 12

adduser --system --home /var/lib/htpc/ htpc
vipw, change htpc shell to /bin/bash
apt-get install build-essential vim xbmc xbmc-standalone ubuntu-restricted-extras mint-meta-gnome-dvd mint-meta-codecs

Download and extract lirc-0.9.0.tar.bz2 from
As I’m using a DangerousPrototypes USB IRToy, all I’m interested in is the IRMan driver

sudo apt-get install libirman-dev
./configure --prefix=/usr/ --with-driver=irman
make install

Copy the SysV startup script from a Debian package into /etc/init.d/, use update-rc.d lirc defaults to put it in all the right runlevel directories

Used my existing Hauppauge A415 remote control definition file, and put it in /etc/lirc/

Edited /etc/lirc/hardware.conf to include the following…

REMOTE_MODULES=”lirc_dev mceusb”

Edited /etc/lirc/lircd.conf to include the following at the end…

include “/etc/lirc/A415-HPG-KG.conf”

Ensure the lirc_dev module is loaded at boot, with echo lirc_dev >> /etc/modules

Start lirc with /etc/init.d/lirc start, and fire up irw. Press some keys on the remote to make sure it works.

Edit /etc/lightdm/lightdm.conf, ensure autologin-user=htpc, and user-session=XBMC

Reboot and bask in XBMC glory

I restored most of my XBMC settings from backups, but the audio settings were of a particular concern. This is what I use to get HDMI passthrough over a NVidia GeForce 8400GS card…

Audio Output : HDMI
Speaker Configuration : 5.1
Audio Output Device : Custom
Custom Audio Device : plughw:0,7
Passthrough output device : Custom
Custom Passthrough device : plughw:0,7

I knew the audio devices courtesy of the output from aplay -l, and some random testing with mplayer got me the results. To test it with mplayer, I just ran mplayer -fs -afm hwac3,hwdts -ao alsa:device=hw=0.7 against the name of a movie I knew had an AC3 soundtrack. Within a couple of seconds the amp was reporting a full AC3 bitstream, and surround sound was filling the living room.

Upstart & pywws

Not content with some shonky bash script launched from rc.local, I had a quick look at Upstart. It’s a million times easier than I expected. Simply stick the following into /etc/init/pywws.conf and let upstart do the rest. If you want to start the app, just run service pywws start after saving it.

Obviously, please tailor the last exec line to suit your own environment.

# pywws - Python Wireless Weather Station Software

# A collection of Python scripts to read, store and process data from
# popular USB wireless weather stations such as Elecsa AstroTouch 6975,
# Watson W-8681, WH-1080PC, WH1080, WH1081 etc.

description "Python Wireless Weather Station"
author "Kyle Gordon "

start on runlevel [345]
stop on runlevel [!345]

respawn # Respawn this process if it dies

respawn limit 10 600 # If you have to respawn 10 times
# in 10 minutes, give up

exec python /usr/local/pywws-10.12_r323/ -v -l /var/lib/weather/data//live_logger.log /var/lib/weather/data/

Networking Serial Ports

i have a variety of gear that I attach to my server in order to monitor and control the home. As is the fashion these days, it’s a USB device that has a serial port on the end of it.

However as the home control software runs on a virtual machine on the main server, the real hardware has to be pushed through to the virtual environment. Some/most virtualization platforms allow you to assign real ports to virtual ports, but running the lowly VMWare Server I had to come up with another solution. Also, pushing the link across the network is preferable as it means the hardware could also be located on a remote device like a Bifferboard, with all the important software still running on the server.

For this I used Socat from

I knocked together a small script that could be run on either the host or guest, and it would run the right commands depending on the hostname of the machine it was run on.

if [ `hostname` = “flat” ]; then
echo “This is flat – the host”
socat -v tcp-l:54321,reuseaddr,fork file:/dev/ttyS0,nonblock,waitlock=/var/run/ttyS0.lock &
elif [ `hostname` = “homeauto” ]; then
echo “This is homeauto – the guest”
socat -vvv pty,link=/tmp/vmodem0,waitslave tcp: &

After that, make it executable, stick it somewhere safe, and then call it from /etc/rc.local or wherever suits you.