Cac/bluetoothRele.py
2015-12-02 02:34:08 +01:00

31 lines
600 B
Python

#!/usr/bin/python
import bluetooth
import sys
bd_addr = "30:14:06:26:04:18" #itade address
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
print 'Connected'
sock.settimeout(1.0)
print sys.argv[1]
sock.send(sys.argv[1])
print 'Sent data'
data = ""
while 1:
try:
data += sock.recv(1024)
data_end = data.find('\n')
if data_end != -1:
rec = data[:data_end]
print data
data = data[data_end+1:]
break
except KeyboardInterrupt:
break
except bluetooth.btcommon.BluetoothError as error:
continue
sock.close()