Mediaboard

Logitech Cordless MediaBoard Pro Wireless Keyboard

Yeah, it doesn't work well with Ubuntu Karmic


UPDATE!  The Gnome Bluetooth applet now works properly with this device in the 10.04 release. Yay!  (The rest of this document is preserved for anybody using an older Ubuntu release.)

The Gnome Bluetooth applet will find the device, and will even seem to pair with it. But it never works. The old hidd stuff still works, although it doesn't maintain a persistent connection via any of the usual means. (Once the device idles out, it's gone.)


Here's how to fix it.

Remove xserver-xorg-input-synaptics. Installed bluez-compat.

Put the following Python script in "/usr/local/sbin/mediaboard_watcher.py", but replace the MAC address with that of your device (find it on the sticker on the bottom):

#!/usr/bin/python2.6
#
# A hack to make the Logitech Mediaboard Pro(tm) work on Karmic+PS3.

from subprocess import *

import time

KB_ADDR = '00:07:61:E5:E0:7A'
HIDD_BIN = '/usr/bin/hidd'
INTERVAL = 5


def Paired(addr):
  hidd_show = Popen([HIDD_BIN, '--show'], stdout=PIPE,
                    stderr=PIPE).communicate()[0]
  return addr in hidd_show


def main():
  addr = KB_ADDR

  while True:
    while Paired(addr):
      time.sleep(INTERVAL)
    Popen([HIDD_BIN, '--connect', addr], stdout=PIPE, stderr=PIPE)
    time.sleep(INTERVAL)
 

if __name__ == '__main__':
  main()


Then add the following to /etc/rc.local:

/usr/local/sbin/mediaboard_watcher.py &


That's all. This checks that the device is paired every few seconds. If not, it re-pairs.

Reading data from the Mediaboard


For fun, I played with connecting directly to the mediaboard via Python.  You'll need PyBluez 0.17 to connect via L2CAP; there's a bug in the default version on Karmic.

Replace the MAC address with yours, and this script should connect to the device and read raw data back from it.

#!/usr/bin/python -u

import bluetooth
import sys

KB_ADDR = '00:07:61:E5:E0:7A'
PSM = 19

def Notice(str):
  sys.stdout.write(str)

def Connect(addr, psm):
 
  found = False

  # Loop through device discovery until target is acquired.
  Notice('Searching..')
  while not found:
    Notice('.')
    addrs = bluetooth.discover_devices(duration=1)

    if addr in addrs:
      found = True
      Notice(' success!\nFound "%s".\n' % bluetooth.lookup_name(addr))

  # Establish socket.
  Notice('Establishing connection...')
  sock = bluetooth.BluetoothSocket(bluetooth.L2CAP)
  sock.connect((addr, PSM))
  Notice('success!\n')
  return sock


def main():
  addr = KB_ADDR
  psm = PSM

  while True:
    sock = Connect(addr, psm)
    data = 'foo'
    while len(data):
      try:
        data = sock.recv(1024)
      except bluetooth.btcommon.BluetoothError:
        sock.close()
        break
      print '(%2s) %s' % (len(data),data.encode('hex'))
 

if __name__ == '__main__':
  main()
Comments