Skip to content

Instantly share code, notes, and snippets.

@hackolite
Last active January 6, 2016 23:05
Show Gist options
  • Save hackolite/34ce1a3475ed96c188f3 to your computer and use it in GitHub Desktop.
Save hackolite/34ce1a3475ed96c188f3 to your computer and use it in GitHub Desktop.
# simple inquiry example
# votre module bluetooth doit etre connecte au prealable
import bluetooth
import sys
nearby_devices = bluetooth.discover_devices(lookup_names=True)
print("found %d devices" % len(nearby_devices))
for addr, name in nearby_devices:
print(" %s - %s" % (addr, name))
#mettre l'addresse mac de votre device
bd_addr = "20:15:05:11:00:99"
# a verifier
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
try:
while True:
sock.send("d")
data = sock.recv(1024)
if len(data) == 0: break
print("received [%s]" % data)
except IOError:
pass
sock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment