For some developers, working with wireless technologies can be daunting -- and sometimes downright intimidating. All communication is wireless, so you can't just "look up" and see, for instance, 1 MB of data going by. In addition, it is really difficult to debug wireless applications once they are deployed to a mobile device, since you don't have access to system traces or log files to pinpoint the errors while the application is running. This technical article addresses the following tasks:
Contents
I love using the Sun Wireless Toolkit for CLDC. It is a great tool, and it's very handy when I need to create Java ME applications that adhere to the latest and greatest Java ME JSR specifications. However, the Java ME emulator in the Sun Wireless Toolkit has no means to access or communicate with actual Bluetooth hardware, which means that I don't have the ability to fully test my application with the Sun Wireless Toolkit after I start to make API calls that rely on functioning Bluetooth hardware. Because of this problem, developers are left in a difficult situation when they need to develop, test, and debug JSR-82 applications. Additionally, testing your Java ME Bluetooth applications directly on your JSR-82 device is impractical since you don't have access to the The good news is that you're going to learn how to construct a low-cost solution that allows you to install, debug, and test your JSR-82 applications on your computer. I'm going to introduce to you the Mpowerplayer, a CLDC emulator for the computer that can be configured to behave like a JSR-82 Bluetooth-enabled phone. With this configuration, the Mpowerplayer will behave just like a JSR-82 Bluetooth-enabled mobile phone, but you'll have access to the The following list shows the materials that you need to run the example code provided later in this article:
The developer version of the Mpowerplayer is available as a zip file. All you need to do is unzip the file in the location that you desire to install it. Now, for the Mpowerplayer to get access to the Bluetooth device on your PC, copy the Did you know that once you discover the connection URL for your desired Bluetooth service, then you no longer need to employ the device- and service-discovery processes? If you're unfamiliar with what a Bluetooth connection URL looks like, I have provided an example below:
Let us briefly revisit the purposes of the device-discovery and service-discovery processes that apply to all Bluetooth-enabled systems, whether or not if you use the JSR-82 API. The device-discovery process is used to determine what Bluetooth devices are in the vicinity. In the connection URL listed previously, the device represented has the Bluetooth address of
The inner class itself implements the Figure 1 shows the Mpowerplayer running my application during the device-discovery process, and Figure 2 shows the state of mobile application after the device-discovery process is finished. ![]() Figure 1. The Device-Discovery Process in Action
![]() Figure 2. The Device-Discovery Process Completed
Now that we've taken care of the device-discovery process, and we see that the device that we want to connect to is in the list of available devices, let's take another look at the fully qualified connection URL.
As you can see, the device-discovery process lets us know the Bluetooth address (in this case, The service-search process is dependent on knowing the type of service that you want. I want to consume serial data from a Bluetooth-enabled GPS device, and the unique identifier for wireless serial services is
Now, service searching is a blocking I/O operation, so I put the intensive work in the ![]() Figure 3. The Serial Port Service is Found
To reiterate a previous point: now that you have determined the connection URL for your desired device, you no longer need to go through the device- and service-discovery processes for subsequent usage of the remote Bluetooth device. All you need to do is open a connection on the URL. After that, you have everything that you need to communicate with the remote Bluetooth device. Figure 4 shows the operation of another thread-enabled inner class that opens the connection on the URL and then reads the data from the wireless serial port. ![]() Figure 4. Reading Data from the Bluetooth GPS Device
Wait a minute. If we're reading serial data from a GPS device, then where are the latitudes, longitudes, and other global-positioning stuff? Is the data corrupted? Actually, the serial data that you see in Figure 4 is actually encoded in NMEA (National Marine Electronics Association) format, which is the common format for all GPS devices. Part 2 of this technical article shows you how to decode the NMEA data and plot your location on your phone. As you have seen, the Mpowerplayer is a CLDC/MIDP environment that runs on PCs, like the Sun Wireless Toolkit. The added benefit of using the MPowerplayer is that it can be configured to use your Bluetooth hardware in order to test JSR-82 applications without provisioning your application to any mobile devices. I hope that this article has shed some light on the Bluetooth device- and service-discovery processes. As you learned, caching your known connection URLs can greatly increase the performance of your application, since you don't need to employ the device- and service-discovery processes subsequently. In a follow-up article, I continue building on this application to show you how to parse the NMEA data streams and plot your location on a map. Stay tuned! |
| ||||||||||||||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||