Multiple bluetooth connections to NXT?

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Postby ggelan » Wed Mar 24, 2010 2:17 pm

Hi Andy!

Since you told me about the in/outbound relationship, I thought about the following:

Main idea:
If I could set up a ring connection for 3 nxts, then each nxt can be able to communicate with each other directly.

Assume that I have 3 NXTs..
They are named e.g. nxt1 nxt2 nxt3..

First off I use Bluetooth.waitForConnection on all 3 nxts,
then via Bluetooth.connect I create connections for:
nxt1 -> nxt2 & nxt3
nxt2 -> nxt1 & nxt3
nxt3 -> nxt1 & nxt2

Right now I don't have 3 nxts so I can't make any testing, but my professor told me that he had done the ring connection for 3 nxts before, so this should be doable.

I'm just not sure if I'm on the right track of the implementation idea...

So glad if you could give me some hints on this or correct me in case my idea is wrong..
ggelan
New User
 
Posts: 5
Joined: Sun Mar 14, 2010 3:20 pm

Postby gloomyandy » Wed Mar 24, 2010 3:24 pm

Hi,
I assume that what you mean is that...
NXT1 will connect to NXT2
NXT2 will connect to NXT3
NXT3 will connect to NXT1
So each will have a single inbound connection plus an outbound connection. But will be able to talk to any of the other 2 NXTs directly. This should be fine (but because you have multiple connections it will be slower, having multiple connections on an NXT means that the NXT will have to keep asking the Bluecore module to switch from one connection to the other). Also this solution will only work for 3 NXTs if you have four then you are out of luck...

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

Postby ggelan » Thu Mar 25, 2010 10:16 am

Hi Andy,

thanks again!!

That is exactly what I mentioned but somehow expressed a little bit wrong :p

I'm so happy to hear that this will work, my task is only to create the connection first for 3 NXTs, and the latency issue can be ignored since my implementation does not need to react that fast as in pure real time :D

Anyway, thanks alot Andy!!
ggelan
New User
 
Posts: 5
Joined: Sun Mar 14, 2010 3:20 pm

Postby aklarl » Wed Aug 11, 2010 10:19 am

Hey Andy,

I am trying to connect multiple NXTs among each other. I have read that you always recommend not to connect them directly. The NXTs shall rather connect to a PC that transfers the communication between the NXTs. But for my project I should not use any PC, so I tried long to connect multiple NXTs since I found this comment of yours:

gloomyandy wrote:... You may find it works better if you establish the inbound connection before you make the outbound one. I know this works fine...

Andy


So I changed my code so that I first wait for any inbound connection (just for one connection) and then I connect to different other devices (outbound connections). That works pretty good, but I am wondering why it is not working the other way round. I succeeded just one time in connecting to some device first and then waiting for an inbound connection.

Greets
aklarl
New User
 
Posts: 21
Joined: Sun May 30, 2010 10:56 am

Postby gloomyandy » Wed Aug 11, 2010 12:45 pm

Hi,
I'm not sure if there is an actual problem as such I know that I changed some code in this area after thinking that it could cause problems (the changes are in the snapshot not in the current 0.8.5 release). My comment was based upon the fact that all of my testing did things the way I recommended and so I know that things work that way around...

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

Postby aklarl » Wed Aug 11, 2010 1:47 pm

Hi Andy,

ok, then I am a little bit confused why I get these problems with multiple nxts. Firstly, I have to say that I switched to the developer snapshot. That is because as you mentioned in http://lejos.sourceforge.net/forum/viewtopic.php?t=2019 there are some problems with interfaces in version 0.8.5 which unfortunately affected my project. But I am rather sure that at least the first problem mentioned below did occur with the version 0.8.5.

With the developer snapshot, the following is not working:
I have a controller (called johnny) which firstly connects to a device called crownie and then waits for an inbound connection (from the device jenny). However, the method waitForConnection does not return and for the device jenny the call of connect returns null. Here are the classes I use (I start the device crownie first, then the device controller/johnny and then the device jenny).

Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Controller {

   public static void main(String[] args) {
      BTConnection btcCrownie = Bluetooth.connect("Crownie",
            NXTConnection.PACKET);
      System.out.println("conn to crownie");

      BTConnection btcJenny = Bluetooth.waitForConnection();
      System.out.println("conn to jenny");

      Button.waitForPress();

      btcJenny.close();
      btcCrownie.close();
   }
}


Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Crownie {

   public static void main(String[] args) {
      BTConnection btc = Bluetooth.waitForConnection(0, NXTConnection.PACKET);
      System.out.println("conn");

      Button.waitForPress();

      btc.close();
   }
}


Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Jenny {

   public static void main(String[] args) {
      BTConnection btc = Bluetooth.connect("Johnny", NXTConnection.PACKET);
      System.out.println("conn");

      Button.waitForPress();

      btc.close();
   }
}


For three NXTs I have a similar problem. I have a controller which waits at first for an inbound connection (that comes from the device jenny), then connects to a device called crownie, then to a device called josy. The inbound connection and the connection to crownie are initialized correctly, but the third connection to josy is null. The method waitForConnection for the device Josy does not return. Here is the corresponding code:
Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Controller {

   public static void main(String[] args) {
      BTConnection btcJenny = Bluetooth.waitForConnection();
      System.out.println("conn to jenny");

      BTConnection btcCrownie = Bluetooth.connect("Crownie",
            NXTConnection.PACKET);
      System.out.println("conn to crownie");

      BTConnection btcJosy = Bluetooth.connect("Josy", NXTConnection.PACKET);
      System.out.println("conn to josy");

      Button.waitForPress();

      btcJenny.close();
      btcCrownie.close();
      btcJosy.close();
   }
}


Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Jenny {

   public static void main(String[] args) {
      BTConnection btc = Bluetooth.connect("Johnny", NXTConnection.PACKET);
      System.out.println("conn");

      Button.waitForPress();

      btc.close();
   }
}


Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Crownie {

   public static void main(String[] args) {
      BTConnection btc = Bluetooth.waitForConnection(0, NXTConnection.PACKET);
      // BTComm btcomm = new BTComm(0);
      System.out.println("conn");

      Button.waitForPress();

      btc.close();
   }
}


Code: Select all
import lejos.nxt.Button;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

public class Josy {

   public static void main(String[] args) {
      BTConnection btc = Bluetooth.waitForConnection(0, NXTConnection.PACKET);
      System.out.println("conn");

      Button.waitForPress();

      btc.close();
   }
}


I hope I am not annoying you with my never ending post ! :?
aklarl
New User
 
Posts: 21
Joined: Sun May 30, 2010 10:56 am

Postby gloomyandy » Wed Aug 11, 2010 2:18 pm

As I said I'm not surprised that there are problems if you already have a connection open and then call waitForConnection. This kind of operation has probably been used by very few (possible none). However I'm surprised that you are having problems with the second case (since my test program does pretty much that - it actually connects one NXT to three others and has a connection from a PC to it). Have you tried just connecting from crownie to josy without the other connections?

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

Postby aklarl » Wed Aug 11, 2010 2:50 pm

Andy, I am really impressed! You always touch the right point. I tried connecting crownie and josy and it did work. So I searched for some differences and found that I didn't pair the controller/johnny with josy. So that was why the controller/johnny could not found josy!

Thank you so much!

PS: With the first problem, I will not wonder any more :lol: and just simply accept that there problems. As you recommend, I will first wait for an inbound connection and then create the outbound connections...
aklarl
New User
 
Posts: 21
Joined: Sun May 30, 2010 10:56 am

Postby gloomyandy » Wed Aug 11, 2010 7:12 pm

Hi,
That's great news! Don't worry I will try and check out why your first version did not work... I'd like to understand what the problem is. But the important thing is that you can carry on with your project...

All the best

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

Previous

Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff