Up to 3 connections

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

Moderators: 99jonathan, roger, imaqine

Up to 3 connections

Postby maxdd » Mon Jul 14, 2014 11:53 am

Im trying to establish 3 outbound connections but it seems i just can establish 2.. i've read some posts here that says that it is possibile to do that but even though the devices are paired with the master, it can only establish 2 outbound connections.

here's part of my code...

Code: Select all
int i = 0;
while (i < rd.size() && i < 3) {
RemoteDevice crd = rd.get(i);
BTConnection bcon = Bluetooth.connect(crd);
// BTConnection bcon =
// Bluetooth.connect(rd.get(i).getBluetoothAddress(),
// NXTConnection.PACKET, pin);
LCD.clear();
if (bcon == null) {
   LCD.drawString("Connect fail with", 0, 0);
} else {
   alreadyCommDev.add(crd.getBluetoothAddress());
   bt.add(bcon);
   LCD.drawString("Connected to", 0, 0);
}
LCD.drawString(crd.getFriendlyName(true), 0, 1);
LCD.refresh();
Thread.sleep(1000);
i++;
}


Basically im gettin remoteDevices from the inquiry process (stored in the rd ArrayList) and then checking if i can establish a connection... if i set the while loop like this
Code: Select all
while (i < rd.size() && i < 2)
the program proceeds while with i = 2 (namely i <3) bcon is equal to null


The inbound side code is like this
Code: Select all
LCD.clear();
LCD.drawString("Waiting", 0, 0);
LCD.refresh();
BTConnection btc = Bluetooth.waitForConnection();
LCD.clear();
LCD.drawString("Connected: ", 0, 0);
LCD.refresh();
Thread.sleep(500);
maxdd
New User
 
Posts: 24
Joined: Fri May 23, 2014 6:58 am

Re: Up to 3 connections

Postby gloomyandy » Mon Jul 14, 2014 12:08 pm

You should be able to establish 3 connections. Is it always the same connection that fails? What happens if you connect in a different order? You may want to try adding a delay between the connection attempts. Even better I'd be tempted to actually exchange data with the newly connected device to ensure the connection is established. If you are still having problems then try and create a small simple test program, this will help anyone else recreate the issue and may even help you discover what is causing the problem (sometimes some other part of your more complex problem is the source of the issue). Please remember that to recreate this needs 4 NXTs so not many people will be able to help!
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4118
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Up to 3 connections

Postby maxdd » Mon Jul 14, 2014 12:43 pm

So the order of communication is dictated by how the inquiry method populate the ArrayList since "i" always start from zero. I tried to put some delays but no luck... i even tried to communicate integers and im able to do that with the first two NXTs but the problem persists with the last...
if the connection/stream get an exception the third is able to connect with the master but i think i clearly lose the first two


EDIT: if i wait for 10s it seems to work
EDIT2: it seems that the first two connections are quite fast , while the 3rd is quite slow... so im using an incremental delay
maxdd
New User
 
Posts: 24
Joined: Fri May 23, 2014 6:58 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 5 guests

cron
more stuff