• Home
  • Help
  • Search
  • Login
  • Register
Pages: [1]
Author Topic: GuruPlug and PyBluez  (Read 1736 times)
mcfarland
Newbie
*

Karma: 0
Posts: 3


View Profile
« on: September 09, 2010, 07:17:04 AM »

Has anyone gotten the python module PyBluez working on a GuruPlug?  The one I purchased from Globalscale came with pybluez .15 preinstalled, but so far I haven't managed to get it to work.

Bluetooth itself seems to be functioning, as running “hcitool –I hci0 scan” displays a list of nearby Bluetooth devices.

However, attempting to do the same from python (running:  python -c "import bluetooth; bluetooth.discover_devices()")  fails like this:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/bluetooth/bluez.py", line 22, in discover_devices
    raise BluetoothError ("error communicating with local "
bluetooth.btcommon.BluetoothError: error communicating with local bluetooth adapter

Do I need to change a configuration somewhere or do something to free up the Bluetooth adapter from some other program?  Do I need to build & install a newer pybluez?

Thanks in advance for any advice!

 - Mike



Logged

vanmelle52
Newbie
*

Karma: 0
Posts: 2


View Profile
« Reply #1 on: January 06, 2011, 07:36:12 PM »

This is a known bug, at least to the extent it's in the bug database (http://code.google.com/p/pybluez/issues/detail?id=25).  There's also a workaround suggested there, which I've used with some success (though I've also been crashing Python a lot, but I can't tell if it's this code or something else).  Here's the code I use:

import bluetooth
import select

class MyDiscoverer (bluetooth.DeviceDiscoverer) :
    """Kludge to work around bluetooth.discover_devices not working on GuruPlug"""
    def pre_inquiry (self) :
        self.done = False
    def device_discovered(self, address, device_class, name):
        # print "%s - %s" % (address , name)
        if address not in self.discovered_list:
            self.discovered_list.append(address)
    def inquiry_complete(self) :
        self.done = True
    def discover_my_devices(self):
        self.discovered_list = []
        self.find_devices(lookup_names = False)
        while True :
            can_read, can_write, has_exc = select.select ([self ], [ ], [ ])
            if self in can_read :                             
                self.process_event()                               
            if self.done :
                break
        return self.discovered_list

Then instead of calling bluetooth.discover_devices, I do MyDiscoverer().discover_my_devices().

Of course, if you need names and not just addresses, you can change the lookup_names value.

Cheers.
Logged

Pages: [1]
Print
Jump to: