Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sending information with bluetooth on Raspberry Pi (Python)
# Uses Bluez for Linux
# sudo apt-get install bluez python-bluez
# Taken from:
# Taken from:
import bluetooth
def receiveMessages():
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
client_sock,address = server_sock.accept()
print "Accepted connection from " + str(address)
data = client_sock.recv(1024)
print "received [%s]" % data
def sendMessageTo(targetBluetoothMacAddress):
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((targetBluetoothMacAddress, port))
def lookUpNearbyBluetoothDevices():
nearby_devices = bluetooth.discover_devices()
for bdaddr in nearby_devices:
print str(bluetooth.lookup_name( bdaddr )) + " [" + str(bdaddr) + "]"

This comment has been minimized.

Copy link

commented Feb 15, 2019

When I run this code on my Pi 3B+ I get an empty list [] from bluetooth.discover_devices(). Running the graphic interface or sudo bluetoothctl from the command line I see a whole bunch of devices, including my SiliconLabs BGX13P and my Sensirion Humidity and temperature sensor that I am trying to use as guinea pigs. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.