|
Project Information
Featured
Downloads
|
bluez-python - A BlueZ python binding on top of dbus-python Requirements In order to use bluez-python you need following software packages: - Python 2.5 or later - Linux Bluetooth protocol stack (BlueZ) - Python bindings for D-Bus (dbus-python) Installation From a command shell: # python setup.py install Notes - Only supports BlueZ4 API - Checking the doc directory in the BlueZ source package is always a good idea. Contact Li Dongyang <Jerry87905@gmail.com> For additional information, check the page on the BlueZ wiki: http://wiki.bluez.org/wiki/bluez-python an example on discovering devices: #!/usr/bin/env python
import bluez
import gobject
def device_found(address, properties):
print "[ " + address + " ]"
for key in properties.keys():
value = properties[key]
if (key == "Class"):
print " %s = 0x%06x" % (key, value)
else:
print " %s = %s" % (key, value)
manager = bluez.Manager('gobject')
adapter = manager.DefaultAdapter()
adapter.HandleSignal(device_found, 'DeviceFound')
adapter.StartDiscovery()
mainloop = gobject.MainLoop()
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()and another example on pairing a device: #!/usr/bin/env python
import sys
import bluez
import gobject
def reply_device(device):
print device.GetProperties() # print the device's properties on success
def reply_error(error):
raise error
manager = bluez.Manager('gobject')
adapter = manager.DefaultAdapter()
agent = manager.CreateAgent() # use the build-in simple-agent to get a PIN
mainloop = gobject.MainLoop()
adapter.CreatePairedDevice(sys.argv[1], agent, 'DisplayYesNo', reply_handler=reply_device, error_handler=reply_error)
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()
|