Lecture 16Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 16 Bluetooth for MIDlets Rob Pooley

Slides:



Advertisements
Similar presentations
A Wireless Local Area Network (WLAN) is a network that interconnects devices using radio waves. Wireless networking technologies allow devices to communicate.
Advertisements

MIDP Mobile Information Device Profile Johnny Yau CIS 642 Prof. Insup Lee.
BLUETOOTH. INTRODUCTION A look around at the moment! Keyboard connected to the computer, as well as a printer, mouse, monitor and so on. What (literally)
1 Introduction to Bluetooth v1.1 (Part I) Overview Radio Specification Baseband Specification LMP L2CAP.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets, 5e Chapter 14 Wireless Networking Technologies.
Wireless Network Taxonomy Wireless communication includes a wide range of network types and sizes. Government regulations that make specific ranges of.
By Abdullah M. Dalloul… Abdullah M. Dalloul… Salman Y. Mansour Salman Y. Mansour Supervisor. Supervisor. Dr.
CPET 260 Bluetooth. What is Bluetooth? Not IEEE (Wi-Fi) or HomeRF Originally designed to replace wires Short-range, lower-power wireless technology.
1 Mini Course Programming Context-aware Mobile Phones Thomas Bodin IT University of Copenhagen.
Computers Are Your Future © 2008 Prentice-Hall, Inc.
Bluetooth Network Prepared By: Sara Ayad Aldehany.
Bluetooth Introduction The Bluetooth Technology
Stacy Drake Bluetooth Vs. Wi-Fi. What is Bluetooth?
WLAN. A wireless LAN, or WLANLAN WLAN, is a local area network that does not have wired Ethernet connections. A WLAN can be either an extension to a current.
XP New Perspectives on The Internet, Sixth Edition— Comprehensive Tutorial 6 1 Real-Time Communication on the Internet Exploring Wireless Networks Tutorial.
An Introduction to the Java ME Project Jens A Andersson.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 Using the KToolbar Rob Pooley
Chapter 5 Networks Communicating and Sharing Resources
ECE 424 Embedded Systems Design Networking Connectivity Chapter 12 Ning Weng.
Networks A network is a collection of computers and devices connected together via communications devices and transmission media Advantages of a network.
Bluetooth Kirthika Parmeswaran Telcordia Technologies OOPSLA’2000.
1 of6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
Extended Learning Module D
Opportunities in M-Commerce Standards & Applications Nour El Kadri University of Ottawa.
Bluetooth Techniques ECE 591. Overview  Universal short-range wireless capability  Uses 2.4-GHz band  Available globally for unlicensed users  Devices.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
Huda AL-Omair_ networks61 Wide Area Network. Huda AL-Omair_ networks62 What is a WAN? Wide area network or WAN is a computer network covering a wide geographical.
10/15/ Short-Range Radio Frequency Networking B. Ramamuthy.
K. Salah 1 Chapter 15 Wireless LANs. K. Salah 2 Figure 15.1 BSSs IEEE Specification for Wireless LAN: IEEE , which covers the physical and data.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 23 Summing up Rob Pooley
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
King Fahd University of Petroleum & Minerals Electrical Engineering Department EE400 PROJECT Personal Area Networks Instructed by Dr.AlGhadbanPresenters.
BLUETOOTH Created By: Ajay Bahoriya. Agenda Introduction to Bluetooth Bluetooth Basics Mode of operation Technology Security Advantages Integrating BT.
Bluetooth Techniques Chapter 15. Overview of Bluetooth Initially developed by Swedish mobile phone maker in 1994 to let laptop computers make calls over.
SEMINAR ON BLUETOOTH TECHNOLOGY
Jini Architecture Introduction System Overview An Example.
Focus On Bluetooth Security Presented by Kanij Fatema Sharme.
Networking Basics 8th Grade
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
1 of 5 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
Bluetooth In 1994, the L. M. Ericsson company became interested in connecting its mobile phones to other devices without cables. A SIG (Special Interest.
JPMA PROJECT PRESENTATION (ITU) 1 INTRODUCTION BLUETOOTH CHAT DESIGN JAVA ON MOBILE DEVICE Presenters Benjamin Boateng Abass Omer Venkateshwar Rao Namilakonda.
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
Technology By :-. What Is Bluetooth? Designed to be used to connect both mobile devices and peripherals that currently require a wire Short range wireless.
Exploring the World of Wireless James Taylor - COSC 352 Fall 2007.
Welcome Back Cisco Semester 1 & 2 Review. Why are Networks Complex Environments?? They involve: They involve: –Interconnections to networks outside an.
COMPUTER FUNDAMENTALS David Samuel Bhatti
Wired and Wireless network management 1. outline 2 Wireless applications Wireless LAN Wireless LAN transmission medium WLAN modes WLAN design consideration.
Bluetooth Vishwas Sundaramurthy Low-cost, short range, small form-factor radio links Adhoc networks/links between information appliances.
ICT Unit 4: Network and the effects of using them
Paula Valdez 10MO ALFA BASIC CONCEPTS OF NETWORK.
© 2008 Cisco Systems, Inc. All rights reserved.Cisco ConfidentialPresentation_ID 1 Wireless LANs.
What is Bluetooth? A cable-replacement technology that can be used to connect almost any device to any other device Radio interface enabling electronic.
Chapter 1: Wireless Networking/Technology. Wireless Networking Definition: –the technologies that enable computers to communicate using standard network.
Wi-Fi Technology.
Wireless Networks Dave Abbott.
TCP/IP (Original) Application Transport Internet Network Access TCP/IP
Instructor Materials Chapter 6 Building a Home Network
Ad-hoc Networks.
Parts.cat.com Client training 2016.
A Wireless LAN technologies IEEE
BLUETOOTH AND ITS APPLICATION IN MOBILE PHONES
Bluetooth Profiles.
BLUETOOTH Personal Area Networking [ PAN ] over Bluetooth
EUT 122 Skills and Technology in Communication
Short-Range Radio Frequency Networking
Short-Range Radio Frequency Networking
Presentation transcript:

Lecture 16Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 16 Bluetooth for MIDlets Rob Pooley

Lecture 16Programming Handheld and Mobile devices 2 Wireless Ethernet (IEEE b) Based upon time-tested Ethernet standards. Operates in same unlicensed 2.4GHz band as Bluetooth and HomeRF. Optimized for data transmission up to 100 meters within office, campus LANs Waits, retransmits in response to interference (good for data, bad for voice). Wireless Ethernet Compatibility Alliance: –

Lecture 16Programming Handheld and Mobile devices 3 Bluetooth Set of hardware and software standards specifying how devices can communicate wirelessly in unlicensed 2.4GHz band. Optimized for 30 meters or less, Personal Area Networks (PANs). Based upon master-slave relationships in networks of up to eight devices, piconets. Bluetooth Special Interest Group homepage at: – Java APIs for Bluetooth effort: –java.sun.com/jcp/jsr/jsr_082_bluetooth.html

Lecture 16Programming Handheld and Mobile devices 4 What is Bluetooth? The Bluetooth wireless technology was created to solve a simple problem: –replace the cables used on mobile devices with radio frequency waves. The technology encompasses a simple low-cost, low- power, global radio system for integration into mobile devices. Such devices can form a quick ad-hoc secure "piconet" and communicate among the connected devices. This technology creates many useful mobile usage models because the connections can occur while mobile devices are being carried in pockets and briefcases

Lecture 16Programming Handheld and Mobile devices 5 Usage model Bluetooth ∗ usage model is based on connecting devices together, It is focused on three broad categories: –voice/data access points, –peripheral interconnects, and –Personal Area Networking (PAN).

Lecture 16Programming Handheld and Mobile devices 6 Voice/Data Access Points Voice/data access points is one of the key initial usage models and involves connecting a computing device to a communicating device via a secure wireless link. –For example, a mobile computer equipped with Bluetooth technology could link to a mobile phone that uses Bluetooth technology to connect to the Internet to access . –The mobile phone acts as a personal access point. –Even better, the notebook can connect to the Internet while the cell phone is being carried in a briefcase or purse. The Bluetooth usage model also envisages public data access points in the future.

Lecture 16Programming Handheld and Mobile devices 7 Peripheral Interconnects peripheral interconnects involve connecting other devices together as shown

Lecture 16Programming Handheld and Mobile devices 8 Personal Area Networking Personal Area Networking (PAN), focuses on the ad-hoc formation and breakdown of personal networks. Imagine meeting someone in an airport and quickly and securely exchanging documents by establishing a private piconet.

Lecture 16Programming Handheld and Mobile devices 9 Bluetooth on MIDlets javax.bluetooth Interfaces DiscoveryListener L2CAPConnection L2CAPConnectionNotifier ServiceRecord Classes DataElement DeviceClass DiscoveryAgent LocalDevice RemoteDevice UUID Exceptions BluetoothConnectionException BluetoothStateException ServiceRegistrationException javax.obex Interfaces Authenticator ClientSession HeaderSet Operation SessionNotifier Classes PasswordAuthentication ResponseCodes ServerRequestHandler

Lecture 16Programming Handheld and Mobile devices 10 DiscoveryListener The DiscoveryListener interface allows an application to receive device discovery and service discovery events. This interface provides four methods, two for discovering devices and two for discovering services. void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) Called when a device is found during an inquiry. deviceDiscoveredRemoteDeviceDeviceClass void inquiryCompleted(int discType) Called when an inquiry is completed. inquiryCompleted void servicesDiscovered(int transID, ServiceRecord[] servRecord) Called when service(s) are found during a service search. servicesDiscoveredServiceRecord void serviceSearchCompleted(int transID, int respCode) Called when a service search is completed or was terminated because of an error.serviceSearchCompleted

Lecture 16Programming Handheld and Mobile devices 11 Field Summary static int INQUIRY_COMPLETED Indicates the normal completion of device discovery.INQUIRY_COMPLETED static int INQUIRY_ERROR Indicates that the inquiry request failed to complete normally, but was not cancelled.INQUIRY_ERROR static int INQUIRY_TERMINATED Indicates device discovery has been canceled by the application and did not complete.INQUIRY_TERMINATED static int SERVICE_SEARCH_COMPLETED Indicates the normal completion of service discovery.SERVICE_SEARCH_COMPLETED static int SERVICE_SEARCH_DEVICE_NOT_REACHABLE Indicates the service search could not be completed because the remote device provided to DiscoveryAgent.searchServices() could not be reached.SERVICE_SEARCH_DEVICE_NOT_REACHABLE static int SERVICE_SEARCH_ERROR Indicates the service search terminated with an error.SERVICE_SEARCH_ERROR static int SERVICE_SEARCH_NO_RECORDS Indicates the service search has completed with no service records found on the device.SERVICE_SEARCH_NO_RECORDS static int SERVICE_SEARCH_TERMINATED Indicates the service search has been canceled by the application and did not complete.SERVICE_SEARCH_TERMINATED

Lecture 16Programming Handheld and Mobile devices 12 class DiscoveryAgent The DiscoveryAgent class provides methods to perform device and service discovery. A local device must have only one DiscoveryAgent object. This object must be retrieved by a call to getDiscoveryAgent() on the LocalDevice object.

Lecture 16Programming Handheld and Mobile devices 13 Device Discovery There are two ways to discover devices. First, an application may use startInquiry() to start an inquiry to find devices in proximity to the local device. –Discovered devices are returned via the deviceDiscovered() method of the interface DiscoveryListener. The second way is via the retrieveDevices() method. –This method will return devices that have been discovered via a previous inquiry or devices that are classified as pre-known. –(Pre-known devices are those devices that are defined in the Bluetooth Control Center as devices this device frequently contacts.) –The retrieveDevices() method does not perform an inquiry, but provides a quick way to get a list of devices that may be in the area.

Lecture 16Programming Handheld and Mobile devices 14 Service Discovery The DiscoveryAgent class also encapsulates the functionality provided by the service discovery application profile. The class provides an interface for an application to search and retrieve attributes for a particular service. There are two ways to search for services. –To search for a service on a single device, the searchServices() method should be used. –If you don't care which device a service is on, the selectService() method does a service search on a set of remote devices.

Lecture 16Programming Handheld and Mobile devices 15 General structure See: import javax.bluetooth.DiscoveryListener; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.midlet.MIDlet; public class yourMidlet extends MIDlet implements CommandListener, DiscoveryListener { public void startApp() { } public void pauseApp() { } public void destroyApp() { } public void commandAction(Command c, Displayable d) { } public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass) { } public void inquiryCompleted(int param) { } public void serviceSearchCompleted(int param, int param1) { } public void servicesDiscovered(int param, ServiceRecord[] serviceRecord) { } }

Lecture 16Programming Handheld and Mobile devices 16 Device Discovery To use any Bluetooth related methods you need to obtain a reference to the LocalDevice object. This is done with a call to LocalDevice.getLocalDevice(). LocalDevice gives you access to Bluetooth properties for the device, such as Bluetooth address, friendly name and discovery mode. We will use LocalDevice to obtain a DiscoveryAgent. The DiscoveryAgent object gives you access to device discovery and service search

Lecture 16Programming Handheld and Mobile devices 17 import javax.bluetooth.BluetoothStateException; import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.DiscoveryListener; import javax.bluetooth.LocalDevice; import javax.bluetooth.RemoteDevice; import javax.bluetooth.ServiceRecord; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.midlet.MIDlet; public class yourMIDlet extends MIDlet implements CommandListener, DiscoveryListener { private LocalDevice local = null; private DiscoveryAgent agent = null; private Vector devicesFound = null; public void startApp() { /* Add your MIDlet specific code here. * You probably want to show the user * a welcome screen. * The call to doDeviceDiscovery() is * here for the example's sake. You * should call doDeviceDiscovery() when * the user actively asks for it. */ doDeviceDiscovery(); } private void doDeviceDiscovery() { try { local = LocalDevice.getLocalDevice(); } catch (BluetoothStateException bse) { // Error handling code here } agent = local.getDiscoveryAgent(); devicesFound = new Vector(); try { if(!agent.startInquiry(DiscoveryAgent.GIAC,this)) { //Inquiry not started, error handling code here } } catch(BluetoothStateException bse) { //Error handling code here }

Lecture 16Programming Handheld and Mobile devices 18 What happens Device discovery is started using the LocalDevice and DiscoveryAgent objects. Searching with the General Inquiry Access Code (GIAC) parameter will find devices which are general discoverable. The DiscoveryListener parameter is this, meaning our MIDlet. When devices are discovered or the search is complete, events will be delivered to our MIDlet. Then the deviceDiscovered() and inquiryCompleted() methods come into play. When a device is discovered the deviceDiscovered() method of the object this will be called. The parameter remoteDevice will be the discovered device, it is up to us to decide what to do with it. We do not know how many devices will be discovered. A Vector will therefore be an appropriate data structure to save discovered devices. The inquiryCompleted() method is called when the inquiry ends. You should check the status code supplied in the parameter param.

Lecture 16Programming Handheld and Mobile devices 19 public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass) { devicesFound.addElement(remoteDevice); } public void inquiryCompleted(int param) { /* We should give the user an alert based on the inquiry status code */ switch (param) { case DiscoveryListener.INQUIRY_COMPLETED: // Inquiry completed normally, add appropriate code here. break; case DiscoveryListener.INQUIRY_ERROR: // Error during inquiry, add appropriate code here. break; case DiscoveryListener.INQUIRY_TERMINATED: /*Inquiry terminated, caused by agent.cancelInquiry() * Add appropriate code here. */ break; }

Lecture 16Programming Handheld and Mobile devices 20 And so… We now keep discovered devices in the foundDevices Vector by adding them as they are discovered. When our search ends, we check if everything went as expected and can alert the user by adding appropriate code in our switch-statement.

Lecture 16Programming Handheld and Mobile devices 21 Service Search When device discovery is completed it is time to find out which services are offered by the devices. This is accomplished by a service search on the device of interest. The servicesDiscovered() and serviceSearchCompleted() methods must be implemented. They will handle the events occuring when services are found or the service search completes. In addition, code has been added to the doServiceSearch() method. This method will start a service search on the RemoteDevice supplied as parameter.

Lecture 16Programming Handheld and Mobile devices 22 public void serviceSearchCompleted(int transID, int respCode) { switch(respCode) { case DiscoveryListener.SERVICE_SEARCH_COMPLETED: /* * Service search completed successfully * Add appropriate code here */ break; case DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE: // device not reachable, add appropriate code here break; case DiscoveryListener.SERVICE_SEARCH_ERROR: // Error during service search, add appropriate code here break; case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS: // No records found, add appropriate code here break; case DiscoveryListener.SERVICE_SEARCH_TERMINATED: /* * Search terminated, caused by agent.cancelServiceSearch(..) * Add appropriate code here */ break; }

Lecture 16Programming Handheld and Mobile devices 23 public void servicesDiscovered(int transID, ServiceRecord[] serviceRecord) { //Services discovered, keep a reference // to the ServiceRecord array servicesFound = serviceRecord; }

Lecture 16Programming Handheld and Mobile devices 24 private void doServiceSearch(RemoteDevice device) { /* * Service search will always give the default attributes: ServiceRecordHandle (0x0000), ServiceClassIDList (0x0001), ServiceRecordState (0x0002), ServiceID (0x0003) and * ProtocolDescriptorList (0x004). * * We want additional attributes, ServiceName (0x100), * ServiceDescription (0x101) and ProviderName (0x102). * * These hex-values must be supplied through an int array */ int[] attributes = {0x100,0x101,0x102}; /* * Supplying UUIDs in an UUID array enables searching for specific * services. PublicBrowseRoot (0x1002) is used in this example. This will return any services that are public browsable. When searching * for a specific service, the service's UUID should be supplied here. */ UUID[] uuids = new UUID[1]; uuids[0] = new UUID(0x1002); try { agent.searchServices(attributes,u uids,device,this); } catch (BluetoothStateException e) { // Error handling code here } }