Hi Andy
Thanks for the quick reply. I tried creating such a connection. As you recommended, I made sure the devices were all paired up. This is what happens
Node0 creates an outbound connection with Node1 and then waitsForConnection - no problems.
Node1 waits for connection from Node0. Gets connected to Node0. Then Node1 creates a connection with Node2. - no problems
Node2 waits for connection from Node1. Gets connected to Node1. - no problems.
Node2 then creates a connection with Node0... This is where the problem is encountered!!! (Remember at this time Node0 is executing the waitForConnection command)
Node2 says it is connected to Node0. However, Node0 is still stuck in the waitForConnection mode - It does not get connected to Node2
I get an error message in the Node2 screen
Exception: 16
at: 97:5
at: 55:138
My code for outbound connection
- Code: Select all
@Override
public int connect(String nodeName){
//establish connection with a specific device as a master
node = Bluetooth.getKnownDevice(nodeName);
if (node == null){
if (Node.DEBUG) {
Node.debugMessage("Cannot find " + nodeName);
}
//discover and add devices
discoverDevices();
node = Bluetooth.getKnownDevice(nodeName);
}
//try once again
if (node == null){
if (Node.DEBUG) {
Node.debugMessage("Cannot find " + nodeName,0,0,0);
Node.debugMessage("Exiting",0,1);
}
return 0;
} else{
nodeConnection = Bluetooth.connect(node);
byte[] status = Bluetooth.getConnectionStatus();
if (status == null ){
nodeConnection.close();
if (Node.DEBUG) {
Node.debugMessage("Not Connected ",0,0,0);
Node.debugMessage("Exiting",0,1);
}
return 0;
}else{
if (Node.DEBUG) {
Node.debugMessage("Connected");
}
connected = true;
return 1;
}
}
}
My code for inbound connection
- Code: Select all
@Override
public int connect(){
while (!connected){
Node.debugMessage("Waiting...");
nodeConnection = Bluetooth.waitForConnection();
delay(10);
connected = true;
}
Node.debugMessage("Connected...",0,1);
return 1;
}
Node class is the housekeeping/main class that creates the connections and opens input/output streams etc. I have some questions:
1. Can you shed some ideas on what the error means if there is some standard way to decode the error?
2. Is there any other way/trick which I could use to create a ring topology or am I just out of luck?
3. Is there a way I can look into the source code for waitForConnection method and see what may be causing the problem.
Any other insights would be really great. Once again thank you for the reply.