I want to Send a Data from my Raspberry Pi 3B+ to an MIT App that I created. I can send Data from my MIT to Raspberry Pi even to Arduino using rfcomm-server.py that comes from the PyBlueZ. but I cant seem to do the opposite where I should be able to send data from Raspberry Pi to my MIT App.

import bluetooth
server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
server_sock.bind(("", bluetooth.PORT_ANY))

port = server_sock.getsockname()[1]

uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"

bluetooth.advertise_service(server_sock, "SampleServer", service_id=uuid,
                        service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
                        # protocols=[bluetooth.OBEX_UUID]

print("Waiting for connection on RFCOMM channel", port)

client_sock, client_info = server_sock.accept()
print("Accepted connection from", client_info)

while True:
    data = client_sock.recv(1024)
    if not data:
    print("Received", data)
except OSError:


print("All done.")
  • I tinker around rfcomm-client but I cant seem to get around it as I read the documentation. Can someone Help me? Thanks Dec 20, 2021 at 10:29
  • If you have the connection established between MIT & RPi with data being received then you have the hard bit done. It would maybe help if you could share your code and be clearer about what is working and what is not. Share any error messages etc. I would expect that you need to add a send in to the PyBlueZ example server. Something like: client.send(b'hello)`. There are more examples at: blog.kevindoran.co/bluetooth-programming-with-python-3
    – ukBaz
    Dec 20, 2021 at 11:46
  • Yes. I have an established connection between my MIT and RPi. Dec 20, 2021 at 13:16
  • In your code you have added, there is no client_sock.send(). You will need to add one to send data the other way.
    – ukBaz
    Dec 20, 2021 at 13:21
  • I used my Raspberry Pi as a Server based on the code above, in which I can receive a Message from MIT. so I think I cant use code like client.send(b'Hello') because the RPi is the Server not the Client. But to make sure, I did what you advice, but it just make my Code rerun again without spitting out Error. so Im in a Slump. Dec 20, 2021 at 13:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.