Android手机无法连接到PyBluez Server?

时间:2017-10-10 18:38:12

标签: android python bluetooth raspberry-pi pybluez

所以,我一直想制作我自己的raspberry-pi蓝牙音箱,我可以将我的Android手机连接到播放音乐。为此,我在python中偶然发现了PyBluez库,发现我可以用它来创建和宣传蓝牙服务。因此,为了测试我是否可以宣传服务并将我的手机连接到它,我编写了以下代码来试用它:

from bluetooth import * 

server = BluetoothSocket(RFCOMM)
server.bind(("", PORT_ANY))
server.listen(1)
uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
advertise_service(sock=server, name="Bluetooth Speaker", service_id=uuid, service_classes=[SERIAL_PORT_CLASS], profiles=[SERIAL_PORT_PROFILE])

while True: 
        client,addr = server.accept()
        print "Connection from " + addr
        client.close()

然而,虽然该服务确实显示我的手机并不想连接到它。经过一些谷歌搜索,我已经完成了以下所有步骤来解决这个问题,但无济于事:

  1. " DisablePlugins = pnat"在/etc/bluetooth/main.conf
  2. 服务蓝牙重启
  3. hciconfig hci0 up
  4. hciconfig hci0 sspmode 0
  5. hciconfig hci0 piscan
  6. sdptool添加SP
  7. 为了让我的手机正确连接到我的覆盆子pi,我还需要做些什么吗?或者是否有一个我失踪的步骤?

    谢谢!

1 个答案:

答案 0 :(得分:0)

如果这是我想的你可以尝试把它放在终端pulseaudio --start

你可能正在寻找。

此处有更多信息https://www.raspberrypi.org/magpi/bluetooth-audio-raspberry-pi-3/