Reading bluetooth GPS data from a Nokia phone

I have a problem reading data from a MTK bluetooth GPS device from a Nokia phone (7610, Symbian S60).
I wrote a midlet (my phone supports CLDC 1.0/MIDP 2.0) that create a thread to read data
from the device (using RFCOMM protocol), the code is:
package gpsreader.bluetooth;
import javax.microedition.io.*;
import java.io.*;
public class BTrxtx implements Runnable {
private String url = ""; // Connection string to the bluetooth device.
private boolean canRead; // True if possible to read from device.
private boolean canWrite; // True if possible to write to device.
private String btstr = ""; // Last received string.
private int strCounter;
private int byteCounter;
private StreamConnection conn = null;
private InputStream inputstream = null;
private OutputStream outputstream = null;
private boolean newStr;
private static final char[] EOL_BYTES = {'\015','\012'};
public BTrxtx(String u) {
url = u;
canRead = false;
canWrite = false;
strCounter = 0;
byteCounter = 0;
newStr = false;
Thread t = new Thread(this);
t.start();
private void openInput() {
canRead = false;
try {
inputstream = conn.openInputStream();
canRead = true;
}catch(Exception e) {
setBtstr("oin");
System.out.println(e);
private void openOutput() {
canWrite = false;
try {
outputstream = conn.openOutputStream();
canWrite = true;
}catch(Exception e) {
setBtstr("oout");
System.out.println(e);
private void openConn() {
try {
conn = (StreamConnection) Connector.open(url);
openInput();
openOutput();
}catch(Exception e) {
setBtstr("oconn");
System.out.println("Failed to open connection: " + e);
private void closeInput() {
try {
if(inputstream!=null) {
inputstream.close();
}catch(Exception e) {
setBtstr("cin");
System.out.println(e);
private void closeOutput() {
try {
if(outputstream!=null) {
outputstream.close();
}catch(Exception e) {
setBtstr("cout");
System.out.println(e);
private void closeConn() {
try {
closeInput();
closeOutput();
if(conn!=null) {
conn.close();
}catch(Exception e) {
setBtstr("cconn");
System.out.println(e);
public void run() {
openConn();
try {
Thread.sleep(200);
}catch(Exception e) {
try {
int i = 0;
char c;
String s = "";
// Start reading the data from the GPS
while(canRead==true) {
i = inputstream.read(); // read one byte at the time.
if(i==-1) {
closeConn();
try {
Thread.sleep(200);
}catch(Exception e) {
openConn();
try {
Thread.sleep(200);
}catch(Exception e) {
continue;
byteCounter++;
// Every sentence starts with a '$'
if(i==36){
if(s.length()>0) {
strCounter++;
setBtstr(s);
s = "";
c = (char) i;
s += c;
System.out.println("GPS return no data");
setBtstr("BTend");
}catch(Exception e){
setBtstr("BTrun");
System.out.println(e);
private String byte2hex(byte b) {
char[] alphaHex = {'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F',
int low = (int) b & 0x0f;
int hi = (int) (b & 0xf0) >> 4;
String res = String.valueOf(alphaHex[hi]) + String.valueOf(alphaHex[low]);
return res;
public boolean sendData(String data) {
boolean res = false;
try {
if((canWrite==true) && (conn!=null) && (outputstream!=null) && (data!=null)){
StringBuffer rec = new StringBuffer(256);
// Calculate checksum
int index = data.length();
byte checksum = 0;
while(--index>=0) {
checksum ^= (byte) data.charAt(index);
rec.setLength(0);
rec.append('$');
rec.append(data);
rec.append('*');
rec.append(byte2hex(checksum));
System.out.println(">"+rec.toString());
rec.append(EOL_BYTES);
outputstream.write(rec.toString().getBytes());
}catch(Exception e) {
System.out.println(e);
return res;
public int getStrCounter() {
return strCounter;
public int getByteCounter() {
return byteCounter;
public String getBtstr() {
newStr = false;
return btstr;
private void setBtstr(String s) {
newStr = true;
btstr = s;
public boolean receivedData() {
return newStr;
The problem is on method "run" at line:
     i = inputstream.read(); // read one byte at the time.
after reading some data (usually one NMEA string) read method returns -1,
and even if I try to close the connection and re-open it, after some other data is read,
the midlet is terminated by the phone with an error (something like "jes-13c-java-comms@1441adE32USER-CBase 40").
The GPS receiver is working, since from my PC I am able to connect with a bluetooth USB dongle and read outputs using RFCOMM.
Thx for any suggestions,
LB.

Work around.
I can not say I solved it, but I managed to get a work around:
I read in another post that there are some problems in thread handling on Nokia phones, so I rewrote the class so that it runs on the main thread and now it seems to work (I can not update the screen while reading from the device, but this isn't a big issue for me).
Just in case anyone is interested here is the final code:
import javax.microedition.io.*;
import java.io.*;
public class BTBrxtx {
private String url = ""; // Connection string to the bluetooth device.
private boolean canRead; // True if possible to read from device.
private String btstr = ""; // Last received string.
private int strCounter;
private int byteCounter;
private StreamConnection conn = null;
private InputStream inputstream = null;
private boolean newStr;
private String s = "";
private static final char[] EOL_BYTES = {'\015','\012'};
public BTBrxtx(String u) {
url = u;
canRead = false;
canWrite = false;
strCounter = 0;
byteCounter = 0;
newStr = false;
openConn();
try {
Thread.sleep(200);
}catch(Exception e) {
private void openInput() {
canRead = false;
try {
inputstream = conn.openInputStream();
canRead = true;
}catch(Exception e) {
setBtstr("oin");
System.out.println(e);
private void openConn() {
try {
conn = (StreamConnection) Connector.open(url);
openInput();
}catch(Exception e) {
setBtstr("oconn");
System.out.println("Failed to open connection: " + e);
private void closeInput() {
try {
if(inputstream!=null) {
inputstream.close();
}catch(Exception e) {
setBtstr("cin");
System.out.println(e);
private void closeConn() {
try {
closeInput();
if(conn!=null) {
conn.close();
}catch(Exception e) {
setBtstr("cconn");
System.out.println(e);
public void readInput() {
try {
int i = 0;
char c;
// Start reading the data from the GPS
while(canRead==true) {
i = inputstream.read(); // read one byte at the time.
if(i==-1) {
closeConn();
try {
Thread.sleep(200);
}catch(Exception e) {
openConn();
try {
Thread.sleep(200);
}catch(Exception e) {
continue;
byteCounter++;
// Every sentence starts with a '$'
if(i==36){
if(s.length()>0) {
strCounter++;
setBtstr(s);
s = "";
c = (char) i;
s += c;
return;
c = (char) i;
s += c;
System.out.println("GPS return no data");
setBtstr("BTend");
}catch(Exception e){
setBtstr("BTrun");
System.out.println(e);
private String byte2hex(byte b) {
char[] alphaHex = {'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F',
int low = (int) b & 0x0f;
int hi = (int) (b & 0xf0) >> 4;
String res = String.valueOf(alphaHex[hi]) + String.valueOf(alphaHex[low]);
return res;
public int getStrCounter() {
return strCounter;
public int getByteCounter() {
return byteCounter;
public String getBtstr() {
newStr = false;
return btstr;
private void setBtstr(String s) {
newStr = true;
btstr = s;
public boolean receivedData() {
return newStr;
Now I call method readInput in the main thread and than use getBtstr to retrieve data.
I'm still interested to know if someone had similar problems and how they have been solved.
Thx

Similar Messages

  • Reading GPS Data from a Bluetooth Receiver

    I have a problem when I connect my mobile to a Bluetooth GPS Receiver using the JSR 82 BTAPI.
    My mobile is reading the NMEA data from the GPS Receiver and analizes the data. The NMEA data from the GPS Receiver is delivered every second.
    It works fine for a few minutes. After approximately 5 minutes my mobile hangs (the screen freezes).
    I am using a Siemens S65 (MIDP-2.0, CLDC-1.0).
    InputStream in = null;
    StreamConnection conn = null;
    conn = (StreamConnection) Connector.open(BtsppURL);
    in = conn.openInputStream();
    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
    int ch = 0;
    //each NMEA Message ends with <CR><LF>
    while ( (ch = in.read()) != '\n') {
              bytearrayoutputstream.write(ch);
    bytearrayoutputstream.flush();
    byte[] b = bytearrayoutputstream.toByteArray();
    String gpsStr = new String(b);Thx for any suggestions,
    RH.

    Hello RH -
    I hope you've resolved your problem by now, but a related problem I've seen under Java - both on Nokia and Siemens phones, is in creating/destroying threads.
    If the BT reading thread is being created and destroyed, this will stop working after a short period of time in my experience.
    Instead, launch a thread to read the GPS data - say every second or two - and implement the timer.sleep inside the thread.
    I'm experiencing the "BT Error Code 4" though on the Siemens S65 phone (a number of posts about this on Siemens Forum), hopefully will have this resolved today.
    Best,
    -- Rich Moore

  • I can't bluetooth my photos from my old phone to my iphone 4. i have paired the devices but my iphone wont accept the data. Please can you help??

    I am trying to send all of m photos to my iphone from my old phone (Nokia N97 mini). I have paired the devices, the iphone says it is connedted but when i try to transfer the data from the Nokia, i get a message saying could not connect.
    Please can you help??
    Thanks

    File transfer by bluetooth is not supported on the iPhone. There are a few apps in the app store that permit the transferring of photos by bluetooth, but this is only iPhone to iPhone. Fact is, you can't do what you're trying to do, so you can quit trying.

  • I purchased a Holux M-1200E Bluetooth GPS Data Logger.  The device paired with my laptop just fine so I know it is working right.  The device will not even show up on my iphone or ipad to pair via bluetooth.  Is there a way to pair without jailbreaking???

    I purchased a Holux M-1200E Bluetooth GPS Data Logger.  The device paired with my laptop just fine so I know it is working right.  The device will not even show up on my iphone or ipad to pair via bluetooth.  Is there a way to pair without jailbreaking???  I haven't had any trouble to date pairing any devic with my iphone or ipad, this is ridiculous!!!!  Is there a way to update my bluetooth settings on my iphone 4s to be able to have this device be recognized???  I love my apple devices, but this is very frustrating.  I bought this Data Logger for a specific purpuse to help out with my Search and Rescue volunteer activities, and I really need help with this!!!  I am hoping apple will help me!!!
    Thanks,
    Melissa

    melissafromlenexa wrote:
    That is not the right device, it is the
    Holux
    M-1200E Bluetooth GPS Logger
    I looked at the same sight for that and it does not say that.  This is the first time I have posted a question, you don't have to be mean about it.  I am trying to get this to work for a good cause. 
    It may be the best source of assistance is the manufacturer of the device. I suspect you will need a specific app for the iPhone to get it to work, but the site is rather ambiguous about that.

  • How do I sync my data from a windows phone to an iPhone 4 iOS 7.1.2

    i need help syncing my data from a windows phone to a iPhone.

    Assuming you have your Windows Phone data synced to Microsoft's Outlook.com, or even Gmail,
    You can setup the Outlook.com or Gmail account in Settings->Email, Contacts, Calendars->Accounts->Add Account
    And it will download all data from there. Email, contacts, etc..
    Other than that, you will have to export all your data from the Windows phone, and then use iTunes to Sync whatever is relevant onto the iPhone.

  • How do I transfer data from my old phone to my new phone?  Old phone works but the screen is broken

    How do I transfer data from my old phone to my new phone?  Old phone still turns on, but screen is broken

    Backup Assistant will download your last saved to network contact/phone numbers. Look on phone menus my Casio has it listed under contacts but mfg's differ on where to actuate. Call *611 and get V rep.

  • Is it possible to remove or edit gps data from photos?

    Just listened to a Mac Roundtable podcast and they were talking about removing or editing gps data from photos taken with an iPhone but they never explained how to do it.
    Is it possible to remove or edit out latitude and longitude info from photo files?

    Thanks for this, though after looking at it I'm not too inclined to use an app that requires getting into the terminal. Way too technical for me. But thanks.

  • Can i get GPS data from my Iphon 4S?

    can i get GPS data from my Iphone 4S?

    There are several apps that will give you lat, long and elevation.  GPS Ally and GPS Recorder are two.

  • Why can't I import gps data from iPhone photos in aperture 3

    I have an iPhone 4 (it's already an old model!) and why can't i still not import GPS-data from photo's on my iPhone 4 in Aperture...
    Importing photos from the iphone just goes fine...

    Richie:
    But do you see the GPS of the iPhone data in Meta data section of the Inspector (set to a preset that shows GPS), as Frank Caggiano asked?
    If the images do import the EXIF data, then you should be able to lift and stamp the GPS coordinates. I do that freuently.
    Select on of your iPhone images and lift the sata
    In the lift&stamp HUD deselect everything but the GPS coordinates, like this.
    If no GPS-coordinates do appear in this setting, then your iPhone images do not have the EXIF info required, and you may need to check the iPhone settings.
    If you see the EXIF data, then you just need to select the DSLR images that were taken at the same location and you can stamp the EXIF data to the DSLR images.
    And after that you should be able to see their locations in the Places view.

  • How to transfer your contact list from a nokia phone to iphone s

    how to transfer your contact list from a nokia phone to iphone s

    Import them from the CD to a supported contact application on your computer, then sync them to your phone.

  • I was just copying my data from stand by phone by using phone to phone data transfer but phone also locked with i cloud login of stand by phone what to do

    i was just copying my data from stand by phone by using phone to phone data transfer but phone also locked with i cloud login of stand by phone what to do

    If it's a hardware problem, then the phone will need to be replaced.
    There is no magic that can fix a hardware problem.

  • I have deleted my sons apple id and data from his old phone by accident as i thought i was resetting it for me to use and now he has lost everything on his new phone and his id etc does not work.  Can someone please explain how i am able to retrieve

    Can someone please shed some light on this???
    I thought i was resetting my son's iphone 4 so that I could use it. But I seem to have erased his icloud/apple id and all of his data from his new phone too.  His Apple ID doesnt work and cant be accessed as it now says it is disabled.  I have tried the iforgot.apple.com website without success and have no idea how to rectify.  I have requested a password change to his email address but that is not working either.
    Please help? 

    That sounds confusing.  First off, don't be too worried. There's practically no way to actually delete an Apple ID or it's purchase history.  You should be able to get to it back somehow.  Secondly, that's likely something that you'll need to talk to a real person on the phone for since it likely requires you to explain that you need access on behalf of your son, (who probably just set some security questions or an email address that you didn't know he put in.)  Just call the appropriate AppleCare phone line (800-APL-CARE in the USA, or see the link below for other countries) and tell them you want to talk about an iCloud account security question.
    Phone Support: Contact Apple for support and service - Apple Support

  • How to read a byte data from maxdb data base

    Dear All,
    I have a issue in reading the data from database table.
    I have a column named as templateData which contains the byte data (biometric template data, which comes from fingerprint device) which is DataType of LONG and CODE of BYTE.
    I am not using the below to get the template data
    Connection con = null;
      Statement stmt = null;
      ResultSet resultSet = null;
    byte[] DbBioData = new byte[1024];
    InitialContext ctx = new InitialContext();
       if(ctx == null)
         throw new Exception("Boom - No Context");
       DataSource ds = (DataSource)ctx.lookup(db_drvstr);
       con = ds.getConnection();
       stmt = con.createStatement();
       resultSet  = stmt.executeQuery(db_query + " where SUBJECT_ID='"+ username +"'");
       if(resultSet.next())
        DbBioData = resultSet.getBytes(1);
        _loc.infoT("verify", "verify::Got BioData From MAXDB" +DbBioData );
        loc.infoT("verify", "verify::Query is: " +dbquery + " where SUBJECT_ID='"+ username +"'" );
    But I am not getting the proper data, could anyone please tell me the way to read the biometric data from data base table.

    Hi Kishore,
    is it me or is there no query definition in that code?
    I see that you concatenate a "db_query" with a string to make up a WHERE clause, but the db_query is nowhere defined before.
    So at least you should provide something like
    stmt = con.createStatement("SELECT templateDate FROM <tablename> ");
    before you do anything with the query.
    Besides this: have you ever heard of SQL injections? Try to use BIND-variables instead of concatenating strings. Otherwise your application will spend much time just with parsing your queries...
    Hmm... possibly the best thing you could do about this is to read the JAVA manual for MaxDB:
    <a href="http://maxdb.sap.com/currentdoc/ef/2de883d47a3840ac4ebb0b65a599e5/content.htm">Java Manual (SAP Library - Interfaces)</a>
    Best regards,
    Lars
    Edited by: Lars Breddemann on Dec 17, 2007 1:12 PM - corrected link

  • Creating a external content type for Read and Update data from two tables in sqlserver using sharepoint designer

    Hi
    how to create a external content type for  Read and Update data from two tables in  sqlserver using sharepoint designer 2010
    i created a bcs service using centraladministration site
    i have two tables in sqlserver
    1)Employee
    -empno
    -firstname
    -lastname
    2)EmpDepartment
    -empno
    -deptno
    -location
    i want to just create a list to display employee details from two tables
    empid firstname deptno location
    and same time update  in two tables
    adil

    When I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list.  When I attempt to edit it, I get an error:
    External List fails when attached to a SQL view        
    Sorry, something went wrong
    Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
    I can edit the view in SQL Manager, so it seems strange that it fails.
    Any advice would be greatly GREATLY appreciated. 
    Thanks,
    Randy

  • I can't read in a date from a txt file

    Im not sure of the code needed to read in a date from the text file, this is an example of the text file:
    1
    2
    2003
    ie,
    day
    month year
    I have to read in this date, this is the set method for the date:
    public void setPurchaseDate (int d, int m, int y)
    new Date(d,m,y);
    And this is the code that I have tried using to readin the date:
      PurchaseDate=(Integer.parseInt(line),Integer.parseInt(line),Integer.parseInt(line));now i know its wrong, I just dont know what the code should be!!
    Cheers

    ok, I am going to go through it and see what values I can and cant read in, here is the code i am trying to use:
    private void addx()
           FileReader fin;
           int noBooks;
           int itemNum;
           String title;
           String subject;
           double costNew;
           double costPaid;
           String isbn;
           double sellingPrice = 0;
           int noAuthors;
           int day;
           int month;
           int year;
            String seperator = "#";
            Book[] book = new Book[9];
            try
                fin = new FileReader("Books.txt");
                BufferedReader buff = new BufferedReader(fin);
                String line = buff.readLine();
                int count= 0;
                //read in Number of books
                noBooks=Integer.parseInt(line);
                while( line != null)
                    //Read in item number
                    itemNum = Integer.parseInt(line);
                    //Read in title
                    title = buff.readLine();
                    //Read in number of authors
                    noAuthors=Integer.parseInt(line);
                    //Read each line in as an author until number of authors reached
                    ArrayList authors = new ArrayList();
                    for(int i=0; i < noAuthors ; i++)
                        authors.add(buff.readLine());
                    //Read in cost new
                    costNew = Double.parseDouble(line);
                    //Read in subject
                    subject = buff.readLine();
                    //Read in ISBN
                    isbn = buff.readLine();              
                    //Read in purchase day
                    day = Integer.parseInt(line);
                    //Read in purchase month
                    month=Integer.parseInt (line);
                    //Read in purchase year
                    year = Integer.parseInt (line);
                    //Read in cost paid
                    costPaid = Double.parseDouble(line);
                    line = buff.readLine();
                    //Pass date, month and year values to array
                    Date purchaseDate =new Date(day,month,year);
                    //Pass values to constructor
                    if (line.equals(seperator))
                        book[count++] = new Book(itemNum, title, authors, subject, purchaseDate,costNew,costPaid,isbn, sellingPrice,noAuthors);
                  // line = buff.readLine();
                System.out.println(book.toString());
            catch(Exception ex)
                System.out.println(ex.toString());
             }

Maybe you are looking for