×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    15

    Question Alerting on BT devices out of range or off

    Hi

    I am working on a BT project using Java (JSR-82). My objective is to maintain a list of BT devices in the vicinity and display an alert if any of the device goes off range or gets switched off or other events that could indicate that the connection is lost.

    The phone runs a small midlet which will monitor the nearby BT devices.


    Here is how I crudely implemented this.

    1.) Discover devices
    2.) Keep found devices in an array/vector
    3.) Discover again
    4.) Keep found devices in a second array/vector
    5.) compare both array/vector for difference
    6.) if there is a difference, play a beep sound
    7.) if no difference, then clear second array and rediscover devices
    8.) loop back to step5


    This crude method somewhat works, however performing multiple device discovery is utterly slow and 'lost' device response is delayed due to this.

    Alternatively, I tried to use the RemodeDevice's getFriendlyName(boolean alwaysAsk), which is supposed to throw an exception if it cant contact the device. This however doesnt seem to work on 6600 or the 6260.

    If any of you can think of any better method, do advise.

    Lastly, the BT devices which I am monitoring has Serial Port Profile and its configured to act as a virtual serial port at 9600 baud. I am not sure how to make a service level connection to it. The examples I see are more like client/server ones. Simply put, if my PC exposes a SPP how can I connect to it from the phone via code?

    My setup is. I have both 6600 and 6260, I am using J2MEWTK 2.2 along with the S60 MIDP package. As my usb bt dongle isnt supported by the s60 emulator, I use the default phone emulator on the WTK.

    I am suprised there is no system level exception/notification of sudden loss of a client!

    Thanks you for your time.
    Jameel

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    15

    Problem Resolved

    After fiddling with the JSR82 for 2 days, I figured out that I was completely heading in the wrong direction.

    1.) Repeatitive device discovery is a bad idea and its not required at all (in my case)

    2.) I already know the BT address of the target device, with this all I had to do was to create a RFCOMM connection to the device and try sending some data. It it goes thru the device is alive and within range. If an exception is thrown, then its off or out of range.

    Here is some code which I tried (lifted from an example at benhui.net, thx dood!). I hope it might help someone trying the same thing.

    public void send_SPP_message(Remotedevice r,String msg, String ip)
    {
    // obtain the URL reference to this service on remote device
    //String url = r.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false );
    //example IP for PEACH
    //String url = "btspp://001B5314257F:1;authenticate=false;encrypt=false;master=false";
    String url = "btspp://"+ip+":1;authenticate=false;encrypt=false;master=false";

    try
    {
    // obtain connection and stream to this service
    StreamConnection con = (StreamConnection) Connector.open( url );

    DataOutputStream out = con.openDataOutputStream();

    // write data into serial stream
    out.writeUTF( msg );
    out.flush();

    System.out.println("Mag sent, device is alive");

    // this wait is artificial, the purpose to do wait until the
    // server side really receive the message before we close the connection
    // in theory, this is not necessary, but when I use the Rococo simulator,
    // sometimes the connection dropped on the server side when I close it here
    // it may be a bug in Rococo simulator.
    Thread.sleep(1000);

    // finish, close output stream
    out.close();

    // now the server should have echo back the string, so we read it
    // using input stream
    //DataInputStream in = con.openDataInputStream();
    //String s = in.readUTF();


    con.close();

    } catch (Exception e)
    {
    //e.printStackTrace();
    String err = e.toString();
    System.out.println("Exception!, Device Not found! :> " + err);
    // playAlert(); play a beep sound

    }
    }

    Cheers
    Jameel

  3. #3
    Regular Contributor
    Join Date
    Oct 2004
    Location
    India
    Posts
    138

    Yeah a small doubt

    Jameel,
    I am trying to do the same thing which you did,
    but in C++,
    i got the basic idea which you used but if you have any sample pieces of code let me know
    -chaitu

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    15

    BT in C++

    Hello

    I have not yet fully gotten the gist of the dev enviroment for C++, hence I went for the Java based solution. However having looked thru some reference materials, it apparently is more efficient in C++.

    I have not played with the BT part in C++, still figuring out "Hello World" and the UI components. However there seems to be a nice example called BlueToothChat from the book Developing Series 60 Applications by EMCC Team and Nokia. The code is available for free dl. I would recomend the book or the Nokia docs on Symbian OS itself before attempting BT work in C++

    http://www.emccsoft.com/devzone/series60_book.html

    HTH
    Jameel

  5. #5
    Regular Contributor
    Join Date
    Oct 2004
    Location
    India
    Posts
    138

    Thanks for your quick response

    i Will look into those examples and come back.
    -chaitu

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    10

    Re: Request for program

    Hi all,

    I need a program for Service Discovery that should search neighbor devices and discover their services. Neighbor devices can be a mobile or Laptop.

    I need a program that should run in PC and discovering the neighbor device services through Bluetooth dongle.

    If you have the program or similar to that, please send it to me through mail. My mail id is shengiv@myway.com

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Re: Alerting on BT devices out of range or off

    hey im also working on a similar project having same requirement!!
    i need a prog which wil run in a PC and detect bluetooth devices in the range using dongle and send them a file in the same PC using bluetooth.
    one of my friends says tat is not possible to detect from PC.
    im not sure of this.
    is u get any idea of how to do it plz let me also know it.
    its v urgent and imp to me..
    my id: art84parthu@gmail.com

    thank you,
    arthy vijayaraghavan

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    1

    Re: Alerting on BT devices out of range or off

    Sorry to report, but the

    http://www.emccsoft.com/devzone/series60_book.html

    link is no longer active.


    Cheers

  9. #9
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Helsinki
    Posts
    63

    Re: Alerting on BT devices out of range or off

    The sample applications of the book seem to be now here:
    http://www.forum.nokia.com/main/1,,40_2,00.html#code

Posting Permissions

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