Skip to content

Instantly share code, notes, and snippets.

@garsaud
Created October 9, 2024 08:39
Show Gist options
  • Save garsaud/0da0cf3f1602e2b0377f9a30b26bdfef to your computer and use it in GitHub Desktop.
Save garsaud/0da0cf3f1602e2b0377f9a30b26bdfef to your computer and use it in GitHub Desktop.
Send and receive text data through bluetooth. Alternative to obsolete rfcomm.
import socket
sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
sock.bind(('XX:XX:XX:XX:XX:XX', 1)) # find local address using `sudo bluetoothctl list`
sock.connect(('YY:YY:YY:YY:YY:YY', 1)) # target device after having paired it
sock.send(b'coucou\n')
sock.recv(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment