×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    11

    Automatic reconnect when Bluetooth connection breaks down

    Hello,

    I'm currently working on a MIDlet which connects to a BT-GPS-Device and parses the GPS data.

    Here is the code I am using:
    Code:
    /**
         * Start thread to connect to the given device and start parsing
         *
         * @param mac The MAC address of the device
         */
        public void connectToDevice(String mac) {
            url  = "btspp://"+mac+":1";
           
            this.start();       
        }
       
        /**
         * Connect to device, read and parse NMEA data until thread is stopped
         */
        public void run() {
            String output = new String("");
            int input;
           
            running = true;
            try {
               
               
                connection = (StreamConnection) Connector.open(url, Connector.READ, true);
               
                reader = new InputStreamReader(connection.openInputStream());
               
                loc = new Location();
               
                while(running) {
                   
                    /* Read input stream until line ends and add character to output string*/
                    while ((input = reader.read()) != 13) {
                        output += (char) input;
                    }
                   
                    output = output.substring(1, output.length() - 1);
                   
                    parseNMEASentence(output);
    
                    output = "";
                }
               
               
               
            } catch (IOException ex) {
                //ToDo: Handle exception
                notifyStateChanged(0,"Error: Connection to GPS failed");
            }
           
        }
    The parsing works fine but I'd like to implement the following feature in addition: When there is a bluetooth disconnect for some reason, my MIDlet should automatically try to reestablish the connection.

    Question 1: When I switch off the GPS device (or the device is out of range) I would assume that the connection breaks down and an Exception is thrown. Unfortunately, this is not the case. No exception is thrown. There is simply no new data to receive. Is it possible that the read() blocks the thread so it is not possible to throw an exception although the connection is broken?

    Question 2: Is there another way to find out if the connection is broken besides from the Exception approach?

    Question 3: The third parameter of Connector.open() is a boolean which indicates if I want to set a timeout or not. Is it possible to set the length of this timeout?

    Thanks for your help in advance.

    Tom

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Target Series? Edition? Model(s)?

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    11

    Re: Automatic reconnect when Bluetooth connection breaks down

    Sorry, I forgot to mention the most important thing: Target device is a Nokia 6680 which is a Series 60 2nd generation as far as i know.

    Tom

Similar Threads

  1. Connect to handset using bluetooth and connection manager
    By christianst in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2004-08-30, 09:31
  2. GPRS Connection from Laptop over Bluetooth
    By ChicMac in forum Bluetooth Technology
    Replies: 1
    Last Post: 2003-05-19, 18:22
  3. Suggestion for resolving PC suite connection via bluetooth
    By Kazi in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-03-14, 19:35
  4. 'Automatic' bluetooth connection with Series 60
    By LongSteve in forum Bluetooth Technology
    Replies: 0
    Last Post: 2002-12-05, 14:52
  5. automatic connection establish via bluetooth to a PDA
    By havelh in forum Bluetooth Technology
    Replies: 0
    Last Post: 2002-08-20, 11:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×