0
votes

So, I've been wanting to make my own raspberry-pi bluetooth speaker that I can connect my android phone to and play music. To do this, I stumbled across the PyBluez library in python, and found that I could use it to create and advertise a bluetooth service. So for testing out to see if I could advertise a service and connect my phone to it, I wrote the following code to try it out:


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()

However, while the service does show up my phone just doesn't want to connect to it. After some googling, I've already done all of the following steps towards solving this problem, but to no avail:

  1. "DisablePlugins = pnat" in /etc/bluetooth/main.conf
  2. Service bluetooth restart
  3. hciconfig hci0 up
  4. hciconfig hci0 sspmode 0
  5. hciconfig hci0 piscan
  6. sdptool add SP

Is there something else that I need to do in order to get my phone to connect properly to my raspberry pi? Or is there a step that I'm missing?

Thank you!

1

1 Answers

0
votes

if it's what i'm thinking you could try putting this in the terminal pulseaudio --start

Might be what you're looking for.

more info here https://www.raspberrypi.org/magpi/bluetooth-audio-raspberry-pi-3/