25
CSE 2200- SOFTWARE DEVELOPMENT PROJECT Name of the project: Wireless controlling pc by using Bluetooth supported mobile. Project supervisor Mr. Sheikh Md. Masudul Ahsan Assistant Professor Department of Computer Science and Engineering Khulna University of Engineering and Technology Khulna-9203 Project submitted by Samiul hoque Prosenjit Shaha Roll: 0507035 Roll:0507012

Control Pc Via Bluetooth Enable Mobile

Embed Size (px)

Citation preview

Page 1: Control Pc Via Bluetooth Enable Mobile

CSE 2200- SOFTWARE DEVELOPMENT PROJECT

Name of the project: Wireless controlling pc by using Bluetooth supported mobile.

Project supervisor

Mr. Sheikh Md. Masudul Ahsan

Assistant Professor

Department of Computer Science and Engineering

Khulna University of Engineering and Technology

Khulna-9203

Project submitted by

Samiul hoque Prosenjit Shaha

Roll: 0507035 Roll:0507012

Page 2: Control Pc Via Bluetooth Enable Mobile

ACKNOWLEDGEMENTS

First of all we acknowledge to almighty ALLAH for completing this project successfully.

Then we are grateful to our project supervisor whose intelligent direction has made the task easier to accomplish. A special thanks to the Head of the Department of Computer science & Engineering to allow us to take several components from the Hardware and Interfacing Lab as also to the teacher who has assigned us this project.

Page 3: Control Pc Via Bluetooth Enable Mobile

INDEX

1. Objectives

2. What is Bluetooth

3. The Bluetooth Protocol Stack

4. RFCOMM

5. Profiles

6. Java Bluetooth API

7. The Basic components of a Bluetooth Application

8. How to make connection between mobile and a PC

9.The Client Program

10. Basic Parts of the Client Program

11.The Java Communication API

12.The Receiver Program

13. The Basic Parts of the Receiver Program

14. Limitations

15. Conclusion

16. Resources

17. Installation Process:

Page 4: Control Pc Via Bluetooth Enable Mobile

Objectives

The objective of this project is to a develop software that will perform basic PC controlling operations and some external device controlling operation using Bluetooth radio signal. Java™.

Page 5: Control Pc Via Bluetooth Enable Mobile

Software advantages1. We can explore all the drives and it’s subfolders and files.

2.We can see Text file and image file in mobile and play and control song in pc.

3. This software enables user to control various windows applications (ex: Restart , Log off , Turn off) from a remote place and no need to use keyboard or mouse.

What is Bluetooth?

Bluetooth is a wireless communication protocol mainly used for short distance and in

devices with low power consumption. Because Bluetooth is capable of communicating in an omni-directional manner of up to 30 feet at 1 Mb/s it is far superior to infrared. Where infrared requires a distance of a few feet or less and requires a direct line of site for transmissions. The Bluetooth core system consists of a radio frequency (RF) transceiver, baseband, and protocol stack. The system offers services that enable the connection of devices and the exchange of a variety of classes of data between these devices. Actually it's a wireless communication protocol that, like HTTP or FTP, operates in a client/server architecture. It uses the 2.4 GHz band. If there are multiple

peripherals to be connected to a computer using RS-232 or USB, then Bluetooth is the ideal solution to use those devices wirelessly.

The Basic features of Bluetooth:

1. 100 Feet Range (Exception Bluetooth Class 1 has 300 feet range).

2. Data transfer speed 1 MB/s.

3. Low power consumption.

4. Omni-directional radio signa

5. Uses 2.4 Ghz-2.482 Ghz radio frequency band

Page 6: Control Pc Via Bluetooth Enable Mobile

The Bluetooth protocol stack

The Bluetooth stack and Bluetooth hardware has close relationship. It works as the driver

for the Bluetooth hardware. The Bluetooth stack is a controlling agent (it could be software, firmware, hardware, or a combination of all three) that implements the Bluetooth protocol and also allows you to control your Bluetooth device programmatically. The Bluetooth stack allows to do these two things:

1. Communicate with other Bluetooth devices

2. Control host Bluetooth device

For example the Bluetooth protocol stack similar with the HTTP protocol stack . A Web browser uses an HTTP protocol stack so that it can receive Web content like HTML pages, images, files, and best of all, Java applets. A Web server also uses an HTTP protocol stack to send out Web content to Web browsers over the network. So, like the HTTP protocol stack, a Bluetooth protocol stack will allow Bluetooth clients and servers to send and receive data over a wireless network.

Layers of the Protocol Stack:

1. Host Controller Interface (HCI)

2. Logical Link Control and Adaptation Protocol (L2CAP) Ø (packet data)

3. Service Discovery Protocol (SDP)

4. RFCOMM Ø (stream data)

5. Wireless Access Protocol (WAP)

6. Object Exchange (OBEX) Ø (object data)

7. Bluetooth Network Encapsulation Protocol (BNEP)

8 . Human Interface Device Protocol (HID)

RFCOMM

RFCOMM is commonly known as the wireless serial port, or the cable replacement

protocol. The name is derived from the fact that the serial ports are called COMM1, COMM2, etc. RFCOMM simulates the functionality of a standard serial port. For instance, a Bluetooth-enabled mobile would use the RFCOMM

layer to synchronize its data to a Bluetooth-enabled PC as if they were physically connected by a cable.

Page 7: Control Pc Via Bluetooth Enable Mobile

Profiles

Bluetooth profile is a designed set of functionality for Bluetooth devices. This enables two

Bluetooth devices to interact properly. To interact Bluetooth-enabled devices , having a Bluetooth stack is not good enough. Those devices also need to implement the same profile. We used the Serial Port Profile that interacts directly with the RFCOMM layer in the Bluetooth protocol stack. This profile is used to create a virtual serial port on Bluetooth-enabled device. For instance,

some Bluetooth kits come with a driver that will allow the operating system to communicate over the virtual serial port as if it were an actual serial port. By using the serial port profile we were able to send stream data to PC. The Bluetooth device in PC receives the stream data through virtual com port. There are many profiles such as:

1. Generic Access Profile2. Service Discovery Application Profile3. Serial Port profile4. Headset profile5. Object Push profile6. File Transfer profile

The Java Bluetooth API

To control the Bluetooth device programmatically, we need J2ME optional package JSR

82. JSR-82 can only be implemented on the J2ME platform. JSR-82 cannot be implemented on the J2SE because the J2SE does not support the generic connection framework. The JSR-82 actually consists of two independent packages:

1. javax.bluetooth (the 13 classes and interfaces that are needed to perform wireless communication with the Bluetooth protocol)

2. javax.obex (the 8 classes that are needed to send objects between devices, independent of the transport mechanism between them)

Page 8: Control Pc Via Bluetooth Enable Mobile

Device Management

LocalDevice, RemoteDevice, and DeviceClass are the classes in the Java Bluetooth specification that form the Generic Access Profile and allow you to perform device management. These classes allow you to query some statistical information about your own Bluetooth device (LocalDevice) and also some information on the devices in the area (RemoteDevice). The DeviceClass object gives you information about the official class of device (CoD) as defined in the Bluetooth specification.

A device class is simply a classification of Bluetooth devices. By simply calling the methods of this class, it can be determined what kind of devices are in the area, like computers, laptops, phones, PDAs, access points, etc. The methods

provided to accomplish this task are getMinorDeviceClass() and getMajorDeviceClass(), both of which return an int. The following table shows some common major and minor device classes.

Major Minor Major class Minor class

Class class Description Description

256 4 Computer Desktop

256 8 Computer Server

256 12 Computer Laptop

256 20 Computer PDA

512 4 Phone Cellular

Page 9: Control Pc Via Bluetooth Enable Mobile

Device Discovery

The Bluetooth device has no idea of what other Bluetooth devices are in the area. Perhaps there are laptops, desktops, printers, mobile phones, or PDAs in the area. The possibilities are endless. In order to find out, the Bluetooth device will use the device discovery classes that are provided in the Java Bluetooth API.

The two classes needed in order for your Bluetooth device to discover remote Bluetooth devices in the area: DiscoveryAgent and DiscoveryListener.

The method DiscoveryAgent is used to make the Bluetooth device search for other devices in the area. The length of the inquiry is totally dependent upon the implementation of the Java Bluetooth specification. The accessCode can be one of the following DiscoveryAgent constants:

NOT_DISCOVERABLE, LIAC, or GIAC.

A reference to a class that implements the DiscoveryListener interface is also passed. When new devices are discovered, event callbacks are passed back to this object. This method will return true if the device successfully went into discovery mode. The startInquiry() method is the only way to perform device discovery without blocking the current thread.

Service Discovery

After locating devices in the area, it would be really nice to see what services those devices offer. The service discovery-related classes in the Java Bluetooth specification implement the Service Discovery Application Profile. The Service Discovery Application Profile, in turn, uses the Service Discovery Protocol (SDP) layer in your Bluetooth stack to find services on remote Bluetooth devices.

The following classes are provided in the Java Bluetooth specification for service discovery:

Discovery Agent, Discovery Listener, Service Record, Data Element, and UUID.

The Service Discovery Database (SDDB) is the central repository for all service records. If a particular JSR-82 implementation does not store

Service records in the SDDB as Java objects, then it must convert them into Service Record objects when a client performs a search for services and a match is found.

Page 10: Control Pc Via Bluetooth Enable Mobile

Communication

As Bluetooth is a communication protocol the official Java Bluetooth API gives three ways to send and receive data. Here two of them are: RFCOMM for stream data and L2CAP for packet data.

RFCOMM is the protocol layer that the serial port profile uses in order to communicate.

How to make connection between a mobile and a PC?

We used a Bluetooth dongle to make a connection between a Bluetooth enabled mobile

and a PC. Unfortunately J2SE doesn’t support the java Bluetooth API JSR-82. So we couldn’t initialize the Bluetooth stack of the dongle in our way. To make the dongle work we used its driver CD to initialize the stack. We send stream data to PC using its serial port profile over the RFCOMM protocol layer.

The Bluetooth dongle works as a receiver or a server and we developed a program for the mobile which works as the client. The client first discovers the Bluetooth devices around it. Then it discovers what services they contain. If the device is a desktop and supports the serial port profile, out client can interact with it over its RFCOMM protocol layer. The client program sends some stream data as command to PC’s virtual communication port. There is a server program in the PC which reads stream data from the communication port and executes those commands.

The client program

We developed a MIDLET for our mobile phone which will work as the client. We gave the

name of our client program “MOBILE MANIA”. Our client program contains all the basic components of a Bluetooth application. It can perform the following tasks:

1. Device Discovery2. Service Discovery

Page 11: Control Pc Via Bluetooth Enable Mobile

3. Communication with a Desktop computer4. Can gain the Bluetooth address of the server to connect5. Can gain the Bluetooth information about the host micro device

This is the basic interface of our client program. From its menu we can choose to discover any Bluetooth device around the host mobile phone or can view the Bluetooth information about the mobile phone. It can discover any device around its Bluetooth range and can show its friendly name.

Basic Parts of the Client program:

Basic components of the client program are

a. Device Discovery

b. Service Discovery

c. Controlling the whole pc

Device Dicovery

Our client program can discover any Bluetooth devices around it. Whenever the Device discovery option is pressed it starts the discovery agent to discover any remote device.

Page 12: Control Pc Via Bluetooth Enable Mobile

Our client device starts in GIAC mode, which means other remote device also can discover our device. Whenever a device is discovered a discovery Listener shows the friendly name of the Bluetooth device.

Service Dicovery

Our client program is also capable of Discovering Services offered by the remote device. Our program search services with the UUID 0x0003 which is the UUID for RFCOMM.

Whenever a service is found our program stores the service records in a service array. Then our program retrieves the service name from a user defined function uuidToName and shows the list of services in the MIDLET screen.

Controlling The PC

DiscoveryAgent agent = device.getDiscoveryAgent();

agent.startInquiry( DiscoveryAgent.GIAC, new Listener() );

agent.searchServices( null, // attributes to retrieve from remote device

new UUID[]{ new UUID( 0x0003) }, /* search criteria, 0x0003 = RFCOMM*/

remote,

new Listener());

ServiceRecord rec = (ServiceRecord)bluetooth.services.elementAt(i);

DataElement e = rec.getAttributeValue( 0x0001 ); // ServiceClassIDList

Enumeration en = (Enumeration)e.getValue();

DataElement e2 = (DataElement)en.nextElement();

Object v = e2.getValue();

Page 13: Control Pc Via Bluetooth Enable Mobile

The PC controlling part of our program can send command to a connected PC to control some basic component of it. The mobile connects with the PC by obtaining the url String that is needed to connect to the device from the ServiceRecord object that we get from service discovery. Our program generates the connecting string automatically by comparing the UUID of Serial Port profile with the UUID of discovered service record objects in the current inquiry. If there is a match then our program saves the connecting string to connect with the remote device.

In the connecting string the part “btspp:\\” means Bluetooth serial port profile, the next number is the Bluetooth address of the remote device which is found by getBluetoothAddress() method. The next digit will be the channel number which will be the index number of the matching UUID in the Service Record. Here master is false which means that the client can only request for data transferring operation. Encrypt and Authenticate is also false.

If there is no matching UUID found then our program rejects to be connected. Our program also checks the characteristics of the remote device. If the remote device is a computer and a desktop then it gives permission to be connected.

The PC Controlling interface

If all the requirements were fulfilled then our PC controlling interface appears. Through this interface we can perform the whole PC controlling operation or can connected to our PC.

if ( u.equals( new UUID( 0x1105 ) )){ //0x1105 UUID for serial port profile

remote=(RemoteDevice)bluetooth.devices.elementAt(deviceDiscoveryUI.getSelectedIndex());

URL="btspp://"+remote.getBluetoothAddress()+":"+i+";master=false;encrypt =false;authenticate=false";

}

DeviceClass cls = (DeviceClass) bluetooth.deviceClasses.elementAt( selectedDevice );

if((cls.getMajorDeviceClass())!=256&&(cls.getMinorDeviceClass())!=4)

alert( "This Device can't perform PC controlling Operation", deviceDiscoveryUI );

con = (OutputConnection) Connector.open( url2,Connector.WRITE );

out = con.openOutputStream();

byte[] data1 = new byte[]{ (byte)nam};

out.write( data1 );

out.flush();

out.close();

Page 14: Control Pc Via Bluetooth Enable Mobile

The Java communications API:

The Java communications API is a package that can be used to write platform-independent

communications applications for technologies such as voice mail, fax, and smartcards.

This Java communications API contains support for RS232 serial ports. Using this API one can:

1. Enumerate ports available on the system. 2. Open and claim ownership of ports.

3. Resolve port ownership contention between multiple applications.

4. Perform asynchronous and synchronous I/O on ports.

5. Receive Beans-style events describing communication port state changes.

The Java communications API does not support unsigned applet access to ports.

Page 15: Control Pc Via Bluetooth Enable Mobile

The Receiver Program:

The receiver program is used in the computer which receives command from the client’s

mobile through serial port and takes necessary steps to perform different actions. İt contains all the necessary informations to receive command from the client and to contrtol computer as well as external electric devices.

When the receiver program is run it always waits for a connection from any bluetooth remote device within it’s range.

Basic Parts of the Receiver Program

The receiver program in the computer can be discussed according to its basic parts.

It has the following basic parts:

i. Creating the Graphical User Interface(GUI) ii. Adding action Listener to the buttonsiii. Writing the current parameters of the port to a configuration file

The receiver is waiting for connection from any Bluetooth enable mobile

Page 16: Control Pc Via Bluetooth Enable Mobile

iv. Creating properties object from configuration filev. Setting parameters to the property objectvi. Handling the exception of opening more than one port at a timevii. Receiving data sent from the clientviii. Comparing string and generating commandsix. Showing the current status of the receiver.

Creating the Graphical User Interface (GUI):

The GUI part of the receiver program contains several labels, buttons, panels, textarea of javax.awt class. The buttons and textareas are added in panels. The whole GUI part is placed in a constructor. The components are placed to their absolute position by using the function setBound( ).As the GUI part is placed in the constructor, whenever the receiver program is run the GUI part becomes visible.

Adding action listener to the buttons:

Here three buttons are used: “Open Port”, ”Close Port” and “EXIT”

The actions to be performed by these buttons are specified in this part of the receiver program. Any exception in performing the specified action is handled here.

Now let us discuss about the actions performed by these three buttons

Open Port:

Once the program is started, the appropriate communication port to receive the data from

client is selected from the list of available communication ports. Then the button “Open Port” is pressed to open the selected port. After the port is successfully opened, it becomes ready to receive data sent from mobile by the client.

Close Port:

When the function of the opened port come to an end, that port should be closed so that another

ports can be opened further. Because in case of serial port only port can be accessed at a time. So after performing action the port should be closed.

EXIT:

If the receiver wishes to be disconnected from client, then the receiver program should be closed.

This is done by pressing the “EXIT” button. After pressing the “EXIT” button if any port remains opened at that time, then that port is closed and after this the program terminates.

Page 17: Control Pc Via Bluetooth Enable Mobile

Showing the current status of the receiver:

In the text area the current status of the receiver remains shown. When the client send new

commands status of the receiver becomes changed. This help anyone near the receiver to know the command that is currently being processed by the computer

Limitations

Though we have developed our software using the platform independent programming

language Java but our software is not totally platform independent at all.Our soft ware can only read data from the serial port. It can generate signal from the PC. So we can perform two way operation. Our software also can’t initialize the Bluetooth stack for dongle. It needs a matching driver for the dongle.

Bluetooth Serial port B is now being open

Confirmation Message after successful connection to a remote device.

Page 18: Control Pc Via Bluetooth Enable Mobile

Conclusion

This software is very much user-friendly. To use it one needs just to press button to control

pc operation. User don’t have to know the Bluetooth address of the server PC. It can discover any Bluetooth device and there services around it.

This software is applicable for all versions of WINDOWS operating system. As maximum computer users feel comfort to use this operating system. We are looking forward to improve our software to make it truly platform independent and to implement the software in two way communication.

Future plan1.Our future plan is to stream music files and video files (.3gp,mp4,avi) from pc.

2. Accessing the internet via pc.

Resources:

1. Jdk 5.52. Net Beans IDE 5.5 3. Java how to program 6th edition

- Deitel & Deitel

4. The Complete Reference J2ME -Herbert Schildt

7 . Bluetooth For Java

-Bruce Hopkins

8 . javax.comm package

Page 19: Control Pc Via Bluetooth Enable Mobile

Installation Process:

There are two parts of our software. One is developed for the mobile phone (client sided) which must be installed in appropriate mobile phone. To do so,

1. Transfer the .JAR and .JAD file to the mobile phone provided in the CD.(recommended to Bluetooth Serial port enable mobile)

2. Install it.

The other part is developed for the personal computer (server sided) which processes the upcoming command and takes actions.This software is bundled with JRE-1.6 and does not requires pre-installation of JAVA. It is also required to attach a blue tooth receiver to your computer if it is not capable of receiving blue tooth signal. It is suggested to use a Bluetooth dongle. Now,

1. Install driver for your Bluetooth receiver device.2. Install the Receiver software. To do that just double click the “Receiver.msi” file and the

software will be automatically installed.3. See (Bluetooth driver software >My Service> Properties>Serial port B )4. Select the port which is used by the Bluetooth receiver from the port list and open it

(suggest to select the Bluetooth serial port B).