Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bluetooth not detected #1

Open
tazzkiller opened this issue Oct 26, 2016 · 4 comments
Open

bluetooth not detected #1

tazzkiller opened this issue Oct 26, 2016 · 4 comments

Comments

@tazzkiller
Copy link

tazzkiller commented Oct 26, 2016

BTGamepad always return " Please turn on bluetooth " after the choice of gamepad or keyboard on ubuntu 16

@lucsmitty
Copy link

ran into the same thing. Looks like in the newer version of pybluez, they took out some of the functions like "DefaultAdapter", so it errors in the try/catch as "Please turn on bluetooth".

Is there a known version of pybluez where this works or an update coming. This looks pretty polished and I'd like to see it working.

@hunterzju
Copy link

I met the same problem.

@wilkinsw
Copy link

I'm also interested in seeing this work. I'll see if I can modify it myself and make a pull-request.

@wilkinsw
Copy link

wilkinsw commented Jun 10, 2018

Fixed that problem, so I'll include the patch. Unfortunately since this was written in such an old version of Bluez I'm sure there's other problems.

For now I think this is the best option:
https://github.com/0xmemphre/BL_keyboard_RPI

Patch for this issue included below

diff --git a/Bluetooth.py b/Bluetooth.py
index 2c47609..6d2267b 100644
--- a/Bluetooth.py
+++ b/Bluetooth.py
@@ -1,5 +1,8 @@
 from bluetooth import *
 import dbus # Used to set up the SDP record
+import sys
+import os
+
 class Bluetooth:
     """docstring for Gamepad"""
     HOST = 0
@@ -17,21 +20,26 @@ class Bluetooth:
         self.sockinter.bind(("",Bluetooth.P_INTR))

         self.bus = dbus.SystemBus()
-        try:
-            self.manager = dbus.Interface(self.bus.get_object("org.bluez", "/"), "org.bluez.Manager")
-            adapter_path = self.manager.DefaultAdapter()
-            self.service = dbus.Interface(self.bus.get_object("org.bluez", adapter_path),"org.bluez.Service")
-        except Exception, e:
-            sys.exit("Please turn on bluetooth")
+        self.manager = dbus.Interface(self.bus.get_object("org.bluez", "/org/bluez"), "org.bluez.ProfileManager1")
+
         try:
             fh = open(sdp,"r")
         except Exception, e:
-            sys.exit("Cannot open sdp_record file")
+            sys.exit("Cannot open sdp_record file, " + str(e))
+
         self.service_record = fh.read()
+
+        opts = {
+            "ServiceRecord":self.service_record,
+            "Role":"server",
+            "RequireAuthentication":False,
+            "RequireAuthorization":False
+        }
+
+        self.manager.RegisterProfile("/bluez/profile", self.UUID, opts)
         fh.close()

     def listen(self):
-        self.service.handle = self.service.AddRecord(self.service_record)
         os.system("sudo hciconfig hci0 class "+self.classname)
         os.system("sudo hciconfig hci0 name "+self.devname)
         self.soccontrol.listen(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants