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)) server_sock.listen(1) port = server_sock.getsockname() uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" bluetooth.advertise_service(server_sock, "SampleServer", service_id=uuid, service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS], profiles=[bluetooth.SERIAL_PORT_PROFILE], # 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) try: while True: data = client_sock.recv(1024) if not data: break print("Received", data) except OSError: pass print("Disconnected.") client_sock.close() server_sock.close() print("All done.")
client.send(b'hello)`. There are more examples at: blog.kevindoran.co/bluetooth-programming-with-python-3
client_sock.send(). You will need to add one to send data the other way.
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.