15 Mart 2019 Cuma

HC-05 python connection

       

import bluetooth

print "Searching for devices..."
print ""
nearby_devices = bluetooth.discover_devices()
num = 0
print "Select your device by entering its coresponding number..."
for i in nearby_devices:
 num+=1
 print num , ": " , bluetooth.lookup_name( i )

selection = input("> ") - 1
print "You have selected", bluetooth.lookup_name(nearby_devices[selection])
bd_addr = nearby_devices[selection]
port = 1
sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
print "Everything is OK, Start to write"
while 1:
 data = raw_input()
 if len(data) == 0: break
 sock.send(data)
sock.close()

Hiç yorum yok: