Bluetooth Communication

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

Moderators: roger, 99jonathan, imaqine

Bluetooth Communication

Postby hulaman » Fri Jan 11, 2013 6:46 pm

Hi
I have LeJOS 0.9.1 in my NXT Bricks. I want to create a sensor network which has ring topology. For e.g. in 3 node case
Node0 - first connects to Node1 and then waits for connection from Node2
Node1 - first Waits for connection from Node0 and then connects to Node2
Node2 - first waits for connection from Node1 and then connects to Node0

Is it possible to create such a network? I found a thread with this discussion before (viewtopic.php?f=5&t=1964). But the discussion was based on LeJOS 0.8.5 version. Since you have a new LeJOS version, is it possible to create such a network among NXTs. In other words, can an NXT at first create a outbound connection using Bluetooth.connect(...) function and then later create an inbound connection using Bluetooth.waitForConnection()? Thank you very much for your response.
hulaman
New User
 
Posts: 3
Joined: Fri Jan 11, 2013 6:35 pm

Re: Bluetooth Communication

Postby gloomyandy » Fri Jan 11, 2013 10:35 pm

It should work, but some users have reported that performing a waitForConnect after you have opened an outbound connection fails. Why not try it and see?

Make sure you have paired the various devices first.

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

Re: Bluetooth Communication

Postby hulaman » Fri Jan 11, 2013 11:19 pm

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.
hulaman
New User
 
Posts: 3
Joined: Fri Jan 11, 2013 6:35 pm

Re: Bluetooth Communication

Postby gloomyandy » Sat Jan 12, 2013 2:19 pm

a) look at the leJOS tutorial it tells you how to decode the exception codes.
b) Try using a separate thread so that you can start the waitForConnect before you do the the connect from node0, it may just be an ordering issue with a separate thread you can start the wait first.
c) The source of leJOS is provided as part of the standard install (you may have to choose to install it though). You can browse it here:
https://sourceforge.net/p/lejos/code/69 ... /nxt/comm/
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bluetooth Communication

Postby hulaman » Fri Jan 25, 2013 3:52 pm

Hi Andy
Thanks. I was able to create a ring topology by using threads. I started the slave thread first and everything works perfectly.
hulaman
New User
 
Posts: 3
Joined: Fri Jan 11, 2013 6:35 pm

Re: Bluetooth Communication

Postby gloomyandy » Fri Jan 25, 2013 4:30 pm

Hi,
Thanks for the feedback. Glad you got it working. I must take a closer look at this and try and work out why it does not work the other way around!

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

Re: Bluetooth Communication

Postby sarahz » Mon Mar 18, 2013 9:07 am

Hello,

I was reading the forum from some time, I cannot say I understand everything but I am trying to.
I am curious of your opinion if there is any possibility to make this work:
My TV is 40EH5450 and am trying to connect (pair) a wireless Bluetooth keyboard (VG-KBD1500/XU). I know that Samsung says is not compatible but I am trying to make it work with a USB Bluetooth adapter.
At this point I think the Tv doesn't know how to use the USB BT adapter to pair the keyboard. I am not sure if there is any solution for this, but any advice would be greatly appreciated.

Thank you.
cheap kids clothes
sarahz
New User
 
Posts: 1
Joined: Mon Mar 18, 2013 9:05 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff