You are not logged in.
Hai, was cleaning up my subdirectory mess, and bumped into a mini mini project from some weeks ago, I was trying to remote control my laptop with my cheap cellphone (it costed 19 euros, included was 12 euros call credit!). As I couldn't get any of the java clients working on it, I quickly wrote a python script that parsed hcidump. It requires the bluetooth daemon, and filesharing. The shared folder contains subfolders which represent commands . Basically you connect with the phone to the share, browsing a folder = executing a command.
I post the script just under the "it worked for me" , it might give others an idea for a work around when java stuff on your phone doesn't work. Be aware that hcidump requires root privileges, so you need to run it as root, so don't count on it being safe
.
#!/usr/bin/env python
#remote.py
""" Author: Dries De Smet
"""
import subprocess
import shlex
cmd = ['hcidump','-a','rfcomm']
def launchLocalCommand(command):
command = shlex.split(command)
return subprocess.Popen(command)
commands = {}
commands["ToggleMute"]="amixer set Master toggle"
commands["volumeDown"]="amixer set Master 5- unmute"
commands["volumeUp"]="amixer set Master 5+ unmute"
commands["Next"]="mpc next"
commands["Previous"]="mpc prev"
commands["TogglePlay"]="mpc toggle"
commands["Shutdown"]="shutdown -h now"
commands["Restart"]="shutdown -r now"
process = subprocess.Popen(cmd,shell=False,stdout=subprocess.PIPE)
append = False
rfcommMsg = ""
while 1:
line = process.stdout.readline().split("\n")[0]
if not line:
break
else:
if "> RFCOMM" in line:
append = True
continue
if "< RFCOMM" in line:
append = False
msg = rfcommMsg.replace(" ","").replace(".","").replace("#"," ").strip().rstrip()
if msg in commands.keys():
launchLocalCommand(commands[msg])
print msg
rfcommMsg = ""
continue
if append is True:
rfcommMsg = ''.join((rfcommMsg,line))
process.close()
Offline
Very nice script, Busata.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
What could be the reason for getting
~ > ./remote.py
Traceback (most recent call last):
File "./remote.py", line 26, in <module>
process = subprocess.Popen(cmd,shell=False,stdout=subprocess.PIPE)
File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Edit: never mind. I was missing bluez-hcidump.
Last edited by riivo (2010-04-28 19:52:14)
Offline