Tuesday, March 24, 2009

How to build Bluetooth Remote Control for desktop machine

Some time ago I was searching for some .NET(CE) stuff and read about the concept of an application that could allow to turn your mobile into a remote control for your desktop machine. I was very impressed by the concept and tried to wrote something similar that could help me control Windows Media Player, PowerPoint slide show and some general windows operations like Logoff User, Shutdown and Restart, Volume Control etc. I am planing to post it with complete source code but currently it needs some finishing steps like removing some unused code and some miner UI improvements. Hopefully I will get some time in near future to get things done.

I developed it for my I-Mate JAM running .NET CE(2.0). Currently .NET does not have any explicit support for bluetooth like java where there is a seperate API (Java Bluetooth API). Microsoft recommends use of sockets for this purpose, using sockets would be really time consuming task because that is relativly a low level programming task so I searched for some open source Bluetooth API that targets microsoft .NET and finally descided to use 32feet.net API. Its an open source API for personal networking.

Hardware Requirements
  1. Develoment Machine capable of running Visual Studio 2005
  2. I-Mate JAM or equvalent PDA device that support Microsoft Bluetooth stack.
  3. Bluetooth dongle for desktop machine, make sure that dongle supports Microsoft Bluetooth stack.
  4. Data cable for PDA
Softwares Requirements
  1. Visual Studio 2005 Professional Edition
  2. .NET CE(2.0) on your PDA (You can install .NET(CE) on I-Mate JAM from here)
  3. Microsoft ActiveSync (You can get it from here)
  4. 32feet.net(InTheHand) API (You can get it from here)
Setting up development environment
  • Install Visual Studio 2005 on development machine
  • Install 32feet.net on development machine. If your hardware is not working with API then you can try following workarund.
  • Now install Microsoft ActiveSync on development machine as well.
  • Finally connect you PDA and machine with datacable and test the connection.
How to control Media Player remotly via Bluetooth
  • First create a Windows form applicaton that will work as server on desktop machine. This applicaton will work as a Bluetooth listner. In 32feet.net samples there is a Remote sample you can use it as guide line.
  • Next you need to find out command messages for Windows Media Player, You can use spy++ for this purpose. For example what is the command message sent against volume up command.
  • Next you need to use import some win32 functions in your C# application for locating the running instance of Winodws Media Player and pass it the command message to performs that action.
  • Finally map some keys that listner recieves via bluetooth and then raises apperoperiate command message for Windows Media Player.
  • Now create Device Application 2.0 for your PDA or you can use the client part of remote sample available with 32feet.net.
  • Once client applicaton is setup properly all you need is to send those keys to desktop machine for wich you define mapping on server component. Once server module will reieve a mapped key for example you have mapped 9 to volume up then it will raise volume up command message for Winodws Media Player and hence will stepup the volume.

No comments: