Thursday, March 27, 2008

Saturday, March 08, 2008

Controlling your Linux PC with your presence

Well the title may be a "bit" misleading. Its literally true as long as you have a bluetooth enabled mobile phone with you. I got the idea of controlling the pc depending on the presence of a Bluetooth enabled phone from KBlueMon, a KDE app that locks the screen if a specified device disappears. It didnt work as well as I would have liked and i wanted the app to do a little bit more. So i decided to try my hand in writing a small no-GUI tool using the BlueZ GNU/Linux Bluetooth stack, that would pause amarok when I(my phone) left the area and would start playback again when I'm around.

Prerequisites:
  • A Bluetooth enabled mobile phone. Bluetooth needs to be turned on but it need'nt be discoverable once you know your phones unique bluetooth id.
  • Standard issue bluetooth dongle hooked up to your pc
  • Any recent GNU/Linux distro(2.6* kernel). I use Kubuntu 7.10 Gutsy Gibbon
  • bluez-utils and libbluetooth-dev installed
I tried many methods for checking whether a device with known bluetooth id is present. The standard hcitool query method was too slow for my purpose. Hence i decided to use a small function provided by the Bluez C development headers. The hci_read_remote_name function is a reverse DNS of sorts. It queries and returns the human readable name of a bluetooth device given its bluetooth address. The bluetooth address is set in the code(too lazy:D). To find out your phones bluetooth id, make it discoverable and run "hcitool scan" from terminal. Rest of the explanation is there in the code. Compile it using the option -lbluetooth

Eg: $g++ -o sense.bin sense.cpp -lbluetooth

To Do: Integrate into system tray and a GUI with many more functions maybe.

Have been running the program for some hours in my pc now. Every time i leave the area with my phone playback stops and when I'm back, playback resumes(WWE style >:) ). Do try this one out if you can and lemme know how it goes :)


Update: Bluetooth id of device to be tracked is now specified as a command line argument.

./bluesense.bin 00:17:E3:A3:59:CB

Also now it performs an extra check if device not found just to ensure the absence of the device before taking any action. This was needed as sometimes the phone takes sometime to respond to successive queries and hence may end up not responding to some queries.

Download code from http://rapidshare.com/files/98519247/bluesense0.2.cpp.html

Tuesday, March 04, 2008

Live for nothing, or die for something.....Your call


I've been a HUGE fan of Rambo ever since school. The fourth rambo film turned me from a rambo fan to a rambo fanatic. Heres something i found when I was googling about rambo and sly stallone in general. These are supposedly sly's 10 tips for life. Ponder on.

10. Believe it! Truly, it can be done and it will.

9. Every day -- every few hours -- see your vision materializing.

8. Don't discuss your dreams. Pursue them!

7. If other people can steal your idea, most likely they will.

6. Don't be afraid of embarrassment while pursuing your goal. It's all part of being committed.

5. Being naïve in business and in understanding human nature is a recipe for disaster.

4. Study people's success stories hard. Study their failures even harder.

3. Enthusiasm is like a wonderful disease -- keep spreading it until everyone is infected.

2. Only choose a goal that -- if you had to -- you'd gladly pursue for free. In order to achieve success, you've got to follow your passion.

1. Most important: If it's not broken, break it. That's how new discoveries are made. That's why everything that changes life is called a breakthrough.