Created
February 24, 2014 12:28
-
-
Save dvas0004/9187515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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