Skip to content

Instantly share code, notes, and snippets.

@kevindoran
Last active January 30, 2023 19:42
Show Gist options
  • Save kevindoran/5428623 to your computer and use it in GitHub Desktop.
Save kevindoran/5428623 to your computer and use it in GitHub Desktop.
A simple Python script to send messages to a sever over Bluetooth using PyBluez (with Python 2).
"""
A simple Python script to send messages to a sever over Bluetooth
using PyBluez (with Python 2).
"""
import bluetooth
serverMACAddress = '00:1f:e1:dd:08:3d'
port = 3
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.connect((serverMACAddress, port))
while 1:
text = raw_input() # Note change to the old (Python 2) raw_input
if text == "quit":
break
s.send(text)
sock.close()
@0xffset
Copy link

0xffset commented Jun 10, 2020

I get an error: AttributeError: 'module' object has no attribute 'BluetoothSocket'. thanks!

@lucasdnsf
Copy link

from bluetooth import *

serverMACAddress = '00:1f:e1:dd:08:3d'
port = 3
s = BluetoothSocket(RFCOMM)
s.connect(serverMACAddress, port)
while 1:
text = raw_input() # Note change to the old (Python 2) raw_input
if text == "quit":
break
s.send(text)
sock.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment