# Uses Bluez for Linux | |
# | |
# sudo apt-get install bluez python-bluez | |
# | |
# Taken from: https://people.csail.mit.edu/albert/bluez-intro/x232.html | |
# Taken from: https://people.csail.mit.edu/albert/bluez-intro/c212.html | |
import bluetooth | |
def receiveMessages(): | |
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) | |
port = 1 | |
server_sock.bind(("",port)) | |
server_sock.listen(1) | |
client_sock,address = server_sock.accept() | |
print "Accepted connection from " + str(address) | |
data = client_sock.recv(1024) | |
print "received [%s]" % data | |
client_sock.close() | |
server_sock.close() | |
def sendMessageTo(targetBluetoothMacAddress): | |
port = 1 | |
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) | |
sock.connect((targetBluetoothMacAddress, port)) | |
sock.send("hello!!") | |
sock.close() | |
def lookUpNearbyBluetoothDevices(): | |
nearby_devices = bluetooth.discover_devices() | |
for bdaddr in nearby_devices: | |
print str(bluetooth.lookup_name( bdaddr )) + " [" + str(bdaddr) + "]" | |
lookUpNearbyBluetoothDevices() |
This comment has been minimized.
This comment has been minimized.
print str(bluetooth.lookup_name( bdaddr )) + " [" + str(bdaddr) + "]" error will look like: |
This comment has been minimized.
This comment has been minimized.
On python3, need to change the print function |
This comment has been minimized.
This comment has been minimized.
yes now no errors shows but still shell window is blank no result is showing |
This comment has been minimized.
This comment has been minimized.
Does anyone know how we can setup multiple channels for a socket over bluetooth? |
This comment has been minimized.
This comment has been minimized.
What guinea pigs? Are you torturing some pigs? |
This comment has been minimized.
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?