Skip to content

Instantly share code, notes, and snippets.

@dvas0004
Created February 24, 2014 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvas0004/9187515 to your computer and use it in GitHub Desktop.
Save dvas0004/9187515 to your computer and use it in GitHub Desktop.
from bluetooth import *
import sys
from subprocess import call
if sys.version < '3':
input = raw_input
addr = None
print("no device specified. Searching all nearby bluetooth devices for")
print("the SL4A service")
# search for the SL4A service
uuid = sys.argv[1]
service_matches = find_service( uuid = uuid, address = addr )
if len(service_matches) == 0:
print("couldn't find the SL4A service =(")
sys.exit(0)
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
print("connecting to \"%s\" on %s" % (name, host))
# Create the client socket
sock=BluetoothSocket( RFCOMM )
sock.connect((host, port))
print("connected.")
try:
while True:
data = sock.recv(1024)
if len(data) == 0: break
print("received %s" % data)
print('--------------------')
if (data == 'firefox\n'):
call(["firefox",""])
sock.send("recv: %s" % data)
except IOError:
pass
print("disconnected")
sock.close()
print("all done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment