Shop OBEX P1 Docs P2 Docs Learn Events
Easy Bluetooth Module And J2ME Mobile Phone — Parallax Forums

Easy Bluetooth Module And J2ME Mobile Phone

alyarosalyaros Posts: 9
edited 2010-11-05 18:47 in BASIC Stamp
Hi All,
I am able to send Data With Easy Bluetooth Module on BS2:
From BS2 to PC.
From PC to BS2.
From Mobile Phone to BS2.
But I can't Send Data From The BS2 to The Mobile Phone Using Bluetooth.

I have JSR-82 complaint Mobile phone - Sony Ericsson W705.
My BS2 Micro controller is hosted on Board of Eduction.

I wrote a Very Simple J2ME Server Application - Below.
And Also a Very Simple BS2 Code For the BS2 Micro Controller - Below.

I Would Really appreciate your assistance with this issue.
Thanks
Al.

================[BS2 Code]================
' {$STAMP BS2}
' {$PBASIC 2.5}

RX CON 2
TX CON 0
Baud CON 84 '9600 Baud

'My Mobile Device Address
addy1 CON $00
addy2 CON $24
addy3 CON $ef
addy4 CON $1a
addy5 CON $89
addy6 CON $51


DEBUG CR,"Establishing SPP connection..."
SEROUT TX, Baud,[$02,$52,$0A,$08,$00,$64,$01,addy6,addy5,addy4,addy3,addy2,addy1,$01,$03]
PAUSE 5000

'Entering Transparent mode
DEBUG CR,"Entering Transparent mode...",CR
SEROUT TX, Baud, [$02,$52,$11,$01,$00,$64,$01,$03]
PAUSE 3000

DO
SEROUT TX, Baud, ["Hello From BT"]
PAUSE 500
DEBUG "Printed Now",CR
LOOP


================[J2ME Code]================

public void run()
{
String inputTxt = mInputBox.getString();
String resultString = "";
try {
resultString = DoWork(inputTxt);
} catch (Exception ex) {
showMessage("Error", ex.toString());
return;
}
showMessage("Do Work Result Value", resultString);
}


private String DoWork(String inputTxt) throws Exception
{

LocalDevice localBTManager = LocalDevice.getLocalDevice();
localBTManager.setDiscoverable(DiscoveryAgent.GIAC);



String hostString =
"btspp://localhost:0000110100001000800000805f9b34fb;
name=SerialPort;
authorize=false";

StreamConnectionNotifier myNotifier =
(StreamConnectionNotifier)Connector.open(hostString);

StreamConnection conn = null;
while (!done){
conn = null;
conn = myNotifier.acceptAndOpen();
if (conn !=null)
{
showMessage("Handle Request","Conn Accepted");
DataInputStream dis=null;
dis = conn.openDataInputStream();
/*Process Request....*/
}
}
return "Done";
}


}

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2010-11-05 18:47
    alyaros wrote: »
    Hi All,
    I am able to send Data With Easy Bluetooth Module on BS2:
    From BS2 to PC.
    From PC to BS2.
    From Mobile Phone to BS2.
    But I can't Send Data From The BS2 to The Mobile Phone Using Bluetooth.

    I have JSR-82 complaint Mobile phone - Sony Ericsson W705.
    My BS2 Micro controller is hosted on Board of Eduction.

    I wrote a Very Simple J2ME Server Application - Below.
    And Also a Very Simple BS2 Code For the BS2 Micro Controller - Below.

    I Would Really appreciate your assistance with this issue.
    Thanks
    Al.

    ================[BS2 Code]================
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    RX CON 2
    TX CON 0
    Baud CON 84 '9600 Baud

    'My Mobile Device Address
    addy1 CON $00
    addy2 CON $24
    addy3 CON $ef
    addy4 CON $1a
    addy5 CON $89
    addy6 CON $51


    DEBUG CR,"Establishing SPP connection..."
    SEROUT TX, Baud,[$02,$52,$0A,$08,$00,$64,$01,addy6,addy5,addy4,addy3,addy2,addy1,$01,$03]
    PAUSE 5000

    'Entering Transparent mode
    DEBUG CR,"Entering Transparent mode...",CR
    SEROUT TX, Baud, [$02,$52,$11,$01,$00,$64,$01,$03]
    PAUSE 3000

    DO
    SEROUT TX, Baud, ["Hello From BT"]
    PAUSE 500
    DEBUG "Printed Now",CR
    LOOP


    ================[J2ME Code]================

    public void run()
    {
    String inputTxt = mInputBox.getString();
    String resultString = "";
    try {
    resultString = DoWork(inputTxt);
    } catch (Exception ex) {
    showMessage("Error", ex.toString());
    return;
    }
    showMessage("Do Work Result Value", resultString);
    }


    private String DoWork(String inputTxt) throws Exception
    {

    LocalDevice localBTManager = LocalDevice.getLocalDevice();
    localBTManager.setDiscoverable(DiscoveryAgent.GIAC);



    String hostString =
    "btspp://localhost:0000110100001000800000805f9b34fb;
    name=SerialPort;
    authorize=false";

    StreamConnectionNotifier myNotifier =
    (StreamConnectionNotifier)Connector.open(hostString);

    StreamConnection conn = null;
    while (!done){
    conn = null;
    conn = myNotifier.acceptAndOpen();
    if (conn !=null)
    {
    showMessage("Handle Request","Conn Accepted");
    DataInputStream dis=null;
    dis = conn.openDataInputStream();
    /*Process Request....*/
    }
    }
    return "Done";
    }


    }
    '
    Looks like this should work.
    '
    I do see a typo that could be throwing off the compiler in your phone?
    '
    ' StreamConnectionNotifier myNotifier =
    ' (StreamConnectionNotifier)Connector.open(hostStrin g);
    '____________________________________________^__
    '
    Could you post the code that talks to the BS2 from your phone?
    This might help indentify the problem.
Sign In or Register to comment.