Mobile Phone Midlet talking to BTReceive

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Mobile Phone Midlet talking to BTReceive

Postby CraigMcCahill » Mon Feb 18, 2008 5:38 pm

Hi,

I've written a MIDlet (using Mobile Processing - http://mobile.processing.org) for sending keypress numbers across Bluetooth from a Mobile to an NXT running LeJos. I'm trying to test this using the BTReceive sample application.

The two apps are happily conecting and the data is being sent :) (just a byte corresponding to the key number)...

...however the data seems to be read in very slowly - there is a pause of about ten seconds and then it catches up before another long pause :(

I've tried reading in a big array of bytes and looping through that but the same thing happens - has anyone got any experience with this sort of problem? I'd be grateful for any help and I'm happy to share code.

Craig
CraigMcCahill
New User
 
Posts: 4
Joined: Mon Feb 18, 2008 5:17 pm

Postby gloomyandy » Mon Feb 18, 2008 8:26 pm

What version of leJOS are you using? If you are using 0.5 then you may want to change the connection into stream mode. By default it will be in packet mode and will be expecting a two byte header at the start of the data (which may be what is causing the problems you are seeing), you can use setIOMode(0) to switch to stream mode. If you are not using 0.5 then you will always be in packet mode.... If this does not help post your leJOS code...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4072
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby CraigMcCahill » Wed Feb 20, 2008 5:45 pm

Hi thank you for the reply,

Yes I was running an earlier version of LeJos and have updated to the latest.

I tried setIOMode(0) on the BTConnection but the problem still remains - there is a pause and the data comes in bursts. This is my code modified from Lawrie Griffith's:-

Code: Select all
public static void main(String [] args)  throws Exception
{
        String connected = "Connected";
        String waiting = "Waiting...";
        String closing = "Closing...";
       
        LCD.drawString(waiting,0,0);
        LCD.refresh();

           BTConnection btc = Bluetooth.waitForConnection();
           //set to stream mode
           btc.setIOMode(0);
          
         LCD.clear();
         LCD.drawString(connected,0,0);
         LCD.refresh();   

         DataInputStream dis = btc.openDataInputStream();
         boolean open = true;
         int n;
         while(open)
         {
            try
            {
               n = dis.read();
               LCD.drawInt(n,7,0,1);
               LCD.refresh();               
            }
            catch(Exception e)
            {
               LCD.clear();
               LCD.drawString("Catch!",0,0);
               LCD.refresh();
               open = false;               
            }            
         }
         dis.close();
         //dos.close();
         Thread.sleep(100); // wait for data to drain
         LCD.clear();
         LCD.drawString(closing,0,0);
         LCD.refresh();
         btc.close();
         LCD.clear();
      
   }


I've tried putting a Thread.sleep call in there as well to give it some room to breath but to no avail - any other clever suggestions? - I can post my Mobile code as well if this helps.

Craig
CraigMcCahill
New User
 
Posts: 4
Joined: Mon Feb 18, 2008 5:17 pm

Postby gloomyandy » Wed Feb 20, 2008 6:40 pm

Hi,
Yes I think it would be good to see the other side of this so please post your phone code. Also you may want to try using the lower level read calls (they are in the BTConection class). Also could you provide more details of what you do (i.e. what the phone app sends), and what happens (i.e. what appears on the screen, how long the gaps are etc.).

All the best

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4072
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby bbagnall » Wed Feb 27, 2008 9:03 pm

Is there any point in trying to make a mobile phone specific class in leJOS? Most people seem to want to use their Bluetooth enabled phone as a remote control. I wonder if there's an API we could copy/invent to make this easier. It might require some MIDP Java code for the mobile phone side of things too.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 6 guests

more stuff