Bluetooth Remote Control Mohammed Maher Alhakim1, Ibrahim Al-Kittani2, Anas Bakleh, Mohammed Swidan3, Dr. Nizar Zarka4 1 IN and CRBT Engineer, Huawei Technologies, Damascus-Syria Phone:+963 94311983, Fax:+963 11 6113710, E-mail:
[email protected] 2 Networks & OS Engineer, BTC Networks, Damascus-Syria E-mail:
[email protected] 3 Information Technology Engineering Faculty of Damascus-Syria 4 Telecom department, Higher Institute for Applied Sciences and Technology (HIAST), P.O.Box: 31983, Damascus-Syria, Phone: +963 94954925, Fax:+963 11 2237710 e-mail:
[email protected] Abstract The aim of this paper is to present our “Bluetooth Remote Control” Application which is based on clientserver application. The client application runs on mobile phone and the server application runs on PC using J2ME and J2SE respectively. This application can be used to control PCs via mobile phone. For example it can open the Internet Explorer, Media player, Power Point, MSN messenger and control the mouse. The application can be also used to control electrical devices using the parallel (LPT) port of PC.
1. Introduction The widespread use of communications and information technology is dramatically improving both the quality and efficiency of mobile applications delivery in the world [1]. The large deployment of Bluetooth wireless networks and increased use of handheld devices like personal digital assistant (PDA) and mobile phones have encouraged mobile vendors to develop their mobile system and applications [2]. In this article we present our “Bluetooth remote control” application which runs on mobile phones and helps users control their PCs and electrical devices remotely.
2. System Design The main system consists of two parts: the client application and the server application. The client application runs on mobile phone and uses J2ME [3]. The server application runs on PC and uses java (JSR 82 standards) and J2SE platform [4]. The connection between the client and the server is realized via the Bluetooth technology.
phone starts searching for activated Bluetooth on PC. Once the PC is found, the phone starts discovering services. The connection between mobile and PC is then established. The phone is now able to send data to the PC. The server program translates the data into commands such as controlling the mouse of the PC or controlling electrical devices such as fans connected to the PC via the parallel port (LPT).
3. System Applications We will present two applications that we have developed: the first one is for controlling the PC from a mobile phone via Bluetooth, and the second is for controlling fans connected to the parallel port of a PC from a mobile phone via Bluetooth.
3.1 Controlling PC via Bluetooth enabled Mobile This application will open a connection between the mobile that controls various applications in PC such as Microsoft Office and Internet Explorer. It can also be used to control the mouse of the PC from the mobile phone via the Bluetooth connection. The application is a client-server application so two programs are needed to be installed in order to implement this application: a program on PC (the server program) and a client program on mobile phone (the client program). The server program starts and waits for a connection from the client. The client searches for Bluetooth devices in range using its Bluetooth search. After finding a proper device (PC), it asks for permission to control it. The server gives back this permission to the mobile phone and allows the control [6].
Four steps are necessary to establish a connection between the client and the server [5]: initialize stuck, discover devices, discover services and open connections as shown in figure 1. In fact, the mobile
ICTTA 2008, Syria
Page 1
server program is an executable program with (exe) extension; it works in startup mode in Windows background. It has no interface.
Figure 2)
Figure 2: Server Program a) Initialize Stack 3.1.2 Client Application The client program should be installed to the mobile phone. It is a J2ME platform based and its tasks include: device discovery, service discovery, opening connection, and controlling the PC [8]. 3.1.3 Client Application interfaces b) Discover devices
C) Discover services
d) Open connection Figure1. Steps to Open Connection
The client application has the following interfaces: start interface, search interface, connection interface and main interface as shown in figure 3. The start interface is the first interface that appears. It has two choices: start application and exit. The second interface is the search interface; its role is to search for devices by pressing the search button. After devices are found (PC name and MAC address) a connection interface menu appears with the following options: research, open connection and exit. The main interface consists of program icons such as Ms Office, media player, Explorer…. If we press the options button we can either research for devices or add connection.
Start interface
Search interface
Main interface
Figure 3: Client Application Interfaces 3.1.1 Server Application 3.1.4 Client Application programming The server program (figure 2) uses RFCOM protocol for opening a Stream Connection Notifier with Bluetooth connecter, defining Authentication, Encryption parameters, and connection UUID number. These tasks should be performed in the above order so that they will function properly. Then the server program waits for the client request [7]. Upon the client request, the server opens a Stream with the client to receive data. The received data is then analyzed in the server to create the appropriate action such as opening MS office program or Internet explorer. The
ICTTA 2008, Syria
To program the client application, we use the J2ME language with the JSR82 technology which supports the Bluetooth functions. The JSR82 contains two basics libraries: javax.bluetooth. and javax.obex. These two libraries provide the following functions to complete the Bluetooth services: getlocaldevice(),getDiscoveryAgent(),startInquiry(), retrieveDevices(),deviceDiscovered(), searchServices(), servicesDiscovered(),
Page 2
getConnectionURL, Connector.open(), getRomteDevice(),send() and receive().
Figure 5. Java Native Interface (JNI)
3.2 Controlling electronic devices This application allows the controlling of electrical devices remotely using the mobile phone. The application consists of the following parts: the client program and the server program. The client program is installed to the mobile; it allows the connection with the PC. The server program is installed to the PC; it allows receiving data from the mobile phone. This data controls the parallel port of the PC where two fans are connected. Pressing certain mobile buttons produces commands to switch the two fans on/off separately or together (see figure 4).
Figure 4: Control Devices Life Cycle The application uses the following techniques: • Sending and receiving data between the mobile phone and the PC via Bluetooth connection using the method explained in section 3.1 • Controlling the parallel port using JAVA language. • Designing and implementing a control circuit that allows connecting two fans to the parallel port of the PC. 3.2.1 Using Java and JNI to control LPT port: Java Language has its unique Java Virtual machine (JVM) which resides above the Operating System layer. This virtual machine executes java programs independently from the working area of the system and produces small sized programs compared to other languages like C++ [6]. On the other hand,
Controlling the system hardware using JVM has become a problem since we can’t access the system hardware resources directly using this machine (i.e. reading or writing in certain memory address and controlling USB or LPT ports). On the contrary, C++ has this feature in a very simple way and without using any additional library. To overcome this problem Sun has developed Java Native Interface (JNI) [9] which allows writing any program in C++ and loads it into JAVA after saving the program in DLL library [6] as shown in figure 5. The steps that Control the parallel port are the following: 1. Writing native Java class to send to the parallel port. This class will also retrieve DLL library which applies the setValue function in C++: public native static void setValue (int i); static { System.loadLibrary (“dlllibrary”) } 2. Translating the class using Javac to produce LPTControl.class and using Javah–jni LPTControl.calss to produce the main file in C++ (see figure 6).
Javac
LPTControl.class
Javah
Name.h
Java
Figure 6. Javac & Javah 3.
4.
5.
Implementing setValue class in C++ by creating cpp file that contains the main file. Translating the C++ program into DLL and save it in the system32 folder ( see figure7). Executing Java class using JVM [10].
Exception s
Functions JNI
Classes
Libraries VM
ICTTA 2008, Syria
Page 3
•
Name.h
C function
System 32
Library.Dll
Figure 7. Translate C to DLL Library In millennium or 98 operating systems, the C++ function is implemented by loading conio.h library using this command: #include “conio.h” _outp(0x378,i) In XP operating system, the system administrator doesn’t have access to this instruction. So the standard output-input library (input32.dll) should be replaced with another library (i.e. www.logix.net) which has the same function name with the same parameters [11]. 3.3. The Electrical circuit Unit: LPT output is controlled using JNI through the server program that receives data from the mobile phone. The electrical circuit controls turning the two fans on/off separately according to LPT outputs. As shown in figure 8, the main components of the circuit are the fans and the transistors D313. The bases of transistors are attached to the LPT ports. When a button is pressed on the mobile phone, the client program, installed in the phone, sends a command to a PC connected to the phone via Bluetooth. The server application, installed in the PC, receives the command, translates it, and sends it to the LPT port. This allows the fan to be turned on or off. This application can be used to control different kinds of electronic devices such as a garage door or a TV with a some modifications in the electrical unit [12].
In order to use the PC Remote control application, we have first to run the sever application in windows background. Then we start the client application in the mobile phone. Clicking on the search menu, the phone starts looking for the server. This will take from 5 to 20 seconds depending on the distance and the number of connected Bluetooth devices. Once the name of the server is found, a new menu appears which allow the user to choose any of the listed programs such as Ms Office, Internet Explorer, and Media Player. The user can even chose the mouse icon so he can use the joystick of the mobile as a mouse of the PC. We tested also the second application which is used to control two fans. When the client application finds the server, new menu appears with the following options: “Pressing number 1” which will turn on the fan-1 “Pressing number 2” will turn on the fan-2. “Pressing number 0” will turn off both fans. “Pressing number 3” will turn on both fans. Our applications were installed and tested on Nokia series 6600 and 7610 and they worked perfectly. The server applications were also tested in windows XP environment and it received and processed all data from the mobile in real time.
5. Conclusion “Bluetooth Remote Control” Making a device able to do things it is not normally asked to do, since the mobile normal job is to receive and make calls, now this mobile can control other devices. Such applications are both easy to use and available for everyone
References [1] John W.Muchow, “Core J2ME technology & MIDP” Sun Microsystems, 2002. [2] Michael Miller, “Discovering Bluetooth”, Sybex Inc, 2001. [3] Michael Juntao Yuan ,“Enterprise J2ME: Developing Mobile Java Applications”, Prentice Hall PTR, 2003. [4] Sony Ericsson “Developing Applications with the Java APIs for Bluetooth (JSR 82)”, 2004. [5] Riku Mettala, “Bluetooth Protocol Architecture”, 1999 [6] Dean A. Gratton, “Bluetooth Profiles”, Prentice Hall PTR, 2002.
Figure 8. Electrical Circuit
4. Test and results
ICTTA 2008, Syria
[7] Jennifer Bray and Charles F. Sturman, “Bluetooth: Connect Without Cables”, Prentice Hall PTR,1st edition, 2000. [8] C Bala Kumar, Paul Kline, Tim Thompson, Morgan Kaufmann, “Bluetooth Application Programming with the
Page 4
Java APIs”, The Morgan Kaufmann Series in Networking, 2003. [9] Beth Streans, “Java Native Interface”, 2000. [10] Dee Bakker, Diane McMichael Gilster, Ron Gilster, “Bluetooth End to End”, Wiley, 2002 [11] Michael Juntao Yuan, “Enterprise J2ME: Developing Mobile Java Applications”, Prentice Hall PTR, 2003. [12] Jonathan Knudsen , “Wireless Java: Developing with J2ME”, Apress, 2003.
ICTTA 2008, Syria
Page 5