Skip to content

Instantly share code, notes, and snippets.

@CynaCons
Created January 17, 2017 15:32
Show Gist options
  • Save CynaCons/8eb02540f87af5594fac489a9dca32c1 to your computer and use it in GitHub Desktop.
Save CynaCons/8eb02540f87af5594fac489a9dca32c1 to your computer and use it in GitHub Desktop.
Simple Python BLE example with python-glib and Bluez5
import dbus
import time
bus = dbus.SystemBus()
#Build a proxy for the Adapter
adapter_proxy = bus.get_object("org.bluez", "/org/bluez/hci0")
#Call the method StartDiscovery from the adapter api then StopDiscovery
adapter_proxy.StartDiscovery(dbus_interface="org.bluez.Adapter1")
time.sleep(10);
adapter_proxy.StopDiscovery(dbus_interface="org.bluez.Adapter1")
#Introspect the adapter
introspection = adapter_proxy.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
#Print the introspection. See the AdvancedProxyExample for xml pretty printing.
print(introspection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment