Thursday, March 29, 2012

Accessing GPS receiver from mobile phone via bluetooth

Accessing GPS receiver from mobile phone via bluetooth

The goal of this project is to read data sent by a GPS receiver via bluetooth on a mobile phone. The data is being transmitted using the bluetooth serial port profile. The GPS receiver uses the NMEA-0183 protocol. This document contains only a description of the mobile device side process that is necessary to get the data from the receiver.
Used Software
  • J2ME (MIDP 2.0, CDLC 1.0)
Used Hardware
  • Nokia 6230 (software version 4.44)
  • RoyalTek BlueGPS (RBT-3000)
Source code
The source code includes a thread-based implementation of the communication between mobile device and GPS receiver. There is a test midlet in Starter.java which displays some information. Description
Establishing connection
The first step is to connect to the bluetooth GPS receiver device. In order to keep it simple, we assume that the bluetooth device address is known (0002c727fc56 in this example). The URL consists of three different parts: URL scheme (btspp: bluetooth serial port profile), bluetooth device address and port.
In the next step an InputStreamReader is being created using the opened connection and its openInputStream() method. Note that both methods may throw an IOException.
        String url = "btspp://0002c727fc56:1";

        javax.microedition.io.StreamConnection connection =
(StreamConnection) Connector.open(url, Connector.READ);


        java.io.InputStreamReader reader =
 new InputStreamReader(connection.openInputStream());

    
Reading data
In this section the characters sent by the GPS receiver are sequentially read in and added to a string until a carriage return character (ASCII code 13) occurs which indicates the end of line. In order to make further processing possible the last character (line feed, ASCII code 10) of the result string is cut off.
        String output;

        int input;



        while ((input = reader.read()) != 13)

            output += (char) input;



        output = output.substring(1, output.length() - 1);
    
Processing data
Each line read in corresponds to a record defined in the NMEA-0183 protocol and can be parsed in further processing steps (see simple J2ME NMEA parser for more details).
Conclusion
Although the process of connecting to the bluetooth device and receiving data is not very complicated there are some difficulties regarding the connection and the used protocol. If the connection is hold up while processing the incoming data (which may take a while) the receiver continually sends data. Depending on the hardware this behavior might cause a buffer overflow (eg on Siemens S65). Therefore it is recommended to disconnect from the GPS receiver while processing data if the processing takes too long and the position data is needed only once in while.

References

Link: http://old.hcilab.org/documents/tutorials/BT_GPS/BT_GPS.htm

 

No comments:

Post a Comment