Bluetooth/USB Data Transfer Issues

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

Moderators: roger, gloomyandy, skoehler

Bluetooth/USB Data Transfer Issues

Postby Mark Lanthier » Tue May 13, 2014 8:35 pm

Hello,

I am having issues passing data back and forth from the EV3 brick to my java PC program via bluetooth. My EV3 connects fine to my java PC program and it does transfer data, but the data being received/sent is quite flaky and sometimes invalid. The same software worked fine when I used my NXT brick, but for the latest 0.8.1 beta version it does not. I recall somewhere in the forum that the bluetooth was at one time "flaky" at this point in the development, is that a known issue ? I'm wondering if it is a problem that is being worked on or whether I can do anything to help. It is hard to debug because it seems that the streams obtained from the BTConnector class are spewing out System.out debugging statements that overwrite my LCD panel. Are these "debug" statements an indication that more needs to be done to get the bluetooth data transfer via i/o streams working properly ? I was wondering if anybody has been able to send data back and forth reliably at this point in the 0.8.1 beta release.

Also, it seems that the previous leJos api had a USB class that allowed me to connect to the NXT via the PC so that I can transfer data via a USB cable. This worked great and was very reliable. Are there any plans to import the USB class into the EV3 version of the leJos API ? I find it very useful when my students in class cannot get their bluetooth connections working. They simply connect via the USB cable to transfer their data. Is anyone working on this for an upcoming release ? Is it hard to import ?

Mark
Mark Lanthier
New User
 
Posts: 9
Joined: Fri Jan 31, 2014 8:15 pm

Re: Bluetooth/USB Data Transfer Issues

Postby gloomyandy » Tue May 13, 2014 8:55 pm

Hi,
I'm not sure what the state is of the "Legacy" Bluetooth code, Lawrie may have more comments on that. To hide the debug output, you can cycle through the screen overlays by pressing both the left and right arrows down at the same time.

With the EV3 we have moved away from the old USB and Bluetooth interfaces and now simply make use of standard networking. This allows you to run things like ssh to the EV3 and allows you to use standard communications classes in your Java programs. For Bluetooth you will need to establish a PAN network from the PC to the EV3, for USB things should pretty much just work if you just plug the device in and make sure you have the RNDIS drivers installed. You can then just use standard Java networking classes to listen for a connection on the EV3 and connect to it from your PC. The IP address of the EV3 when connected via either PAN or USB will be 10.0.1.1 (but leJOS provides code to automatically discover the EV3 address). The same code will work over Bluetooth, USB and WiFi connections.

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

Re: Bluetooth/USB Data Transfer Issues

Postby lawrie » Tue May 13, 2014 9:04 pm

Bluetooth serial communications does have quite a bit of diagnostics in it at the moment, and it has not been tested much. You can get rid of the System.out diagnostics from the LCD screen by pressing Left+Right buttons at the same time. This cycles through the LCD modes.

Is there a reason why you cannot use TCP sockets for communications from the PC to the EV3? It works over Bluetooth (Pan), Wifi and USB using the standard Java Sockets API.

The problem with Bluetooth serial comms is that Java support for it is very poor at the moment. The Bluecove project that we used on the NXT is no longer being developed and does not have an ARM version. We were hoping that Oracle might do something in this area, but it does not seem to be happening at the moment. The code that we currently have uses some of the components of the Bluecove solution and some new Java JNA code. We were hoping that this would be an interim solution. If nothing better materializes, we may have to develop it further.

Bluetooth serial is only really necessary for communicating with the NXT, phones and Bluetooth devices such as GPS devices. TCP sockets is a better solution for communicating with the PC.

There are no plans for the style of USB communications that we had on the NXT, but, as I say, TCP sockets work over TCP. I suppose we could support the NXT interfaces over sockets, but that has no real advantage over using the sockets interface. The NXT appeared to the PC as a type of serial device. The EV3 identifies itself as a network adapter.
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm

Re: Bluetooth/USB Data Transfer Issues

Postby Mark Lanthier » Wed May 14, 2014 2:37 am

Thank you both for replying quickly. Indeed, I will try converting my code to use standard TCP socket connections. That should be fairly reliable. I'm not sure how to set up the PAN or the drivers that you suggested...but I'll browse around a liitle. I appreciate all the work that everyone is doing to get the API working on the EV3. Thank you.

Mark
Mark Lanthier
New User
 
Posts: 9
Joined: Fri Jan 31, 2014 8:15 pm

Re: Bluetooth/USB Data Transfer Issues

Postby lawrie » Wed May 14, 2014 7:00 am

The EV3 automatically sets up the Pan, so it is just a matter of connecting to it. From Windows, you just click on the Bluetooth icon, select Join a Personal Area Network, select your EV3, and then Connect using > Access Point.
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm

Re: Bluetooth/USB Data Transfer Issues

Postby Mark Lanthier » Wed May 14, 2014 6:06 pm

Lawrie and Andy,

The PAN network is not working as I intended. I cannot have the PC connect to the EV3 at 10.0.1.1 because I will be using the software in a lab with up to 30 EV3 devices ... all having the same IP address of 10.0.1.1. So, I need to have each student connect to their individual EV3 via their laptops. The plan was to have a ServerSocket running on the laptop, and have the EV3 connect to the ServerSocket using TCP. However, the EV3 cannot see my PC. I started the server socket on the PC as follows (try/catch exception code not shown for brevity):

ServerSocket serverSocket = new ServerSocket(6000); // 6000 is arbitrary port number
Socket robotSocket = serverSocket.accept(); // waits here for robot to connect, bet never returns! :(

The EV3 code simply does this:

String IPaddress = "134.117.27.230"; // This is my PC's IP address
Socket socket = new Socket(InetAddress.getByName(IPaddress), 6000);

But the call to establish the Socket here returns with a "No Route to Host" exception.
From my PC, I did as suggested ... I clicked on the Bluetooth icon, selected Join a Personal Area Network, selected my EV3, and then Connected using > Access Point. But it will not connect.

Any ideas ?
Mark Lanthier
New User
 
Posts: 9
Joined: Fri Jan 31, 2014 8:15 pm

Re: Bluetooth/USB Data Transfer Issues

Postby lawrie » Wed May 14, 2014 7:05 pm

What happens when you attempt to connect to the access point?

You should make sure that the EV3 and PC can ping each other before trying the socket connection.

I would use the IP address directly as the first parameter to Socket rather than using your getByName call.

I would check that your PC IP address is the correct one for connecting from the EV3. In most home networks there is a local IP address (starting 192 or 10). The one you are using looks like an external IP address, but if it is at your school it will depend on how your school network is set up.
Last edited by lawrie on Wed May 14, 2014 7:23 pm, edited 1 time in total.
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm

Re: Bluetooth/USB Data Transfer Issues

Postby Mark Lanthier » Wed May 14, 2014 7:23 pm

The access point connects fine. I am able to upload and run programs on the EV3 via the eclipse plugin. The EV3 code just doesn't see the PC through my software. Disabling the firewall did not do anything either.
Mark Lanthier
New User
 
Posts: 9
Joined: Fri Jan 31, 2014 8:15 pm

Re: Bluetooth/USB Data Transfer Issues

Postby lawrie » Wed May 14, 2014 7:27 pm

Do you have putty on your PC? I would connect to the EV3 by ssh, e.g. by using putty and logging in as root, no password. Then try to ping the PC IP address.

If that works, use the IP address (as a string) as the first parameter to Socket. I just edited my previous reply, so check that.
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm

Re: Bluetooth/USB Data Transfer Issues

Postby Mark Lanthier » Wed May 14, 2014 7:52 pm

I used Putty and pinging the PC does not work. I tried ping 134.117.27.230 ... and there was no reply :(. I did an experiment by running the Server on my PC and running a test program (using the same code as the EV3...but on the PC). The two programs were able to connect with that IP address. So the IPAddress must be correct. Since I cannot ping the PC from the EV3 ... I guess the PAN network is not really set up properly, or has some issues. I did the steps as Andy suggested ... and it said that I had the connection. Do you think that the problem has something to do with the "direction" of the connection (i.e., EV3 cannot connect to PC, but PC may be able to connect to EV3) ? Has anyone tried yet to do what I am doing ?

Mark
Mark Lanthier
New User
 
Posts: 9
Joined: Fri Jan 31, 2014 8:15 pm

Re: Bluetooth/USB Data Transfer Issues

Postby lawrie » Wed May 14, 2014 9:32 pm

Your PC should have an ip address on the Bluetooth network after you have connected to the Pan. Mine is 10.0.1.10.

You can find it by typing ipconfig on the PC, or connecting to the EV3 with ssh and typing "who".

I could not ping this address but the socket programs worked.

On the PC:

Code: Select all
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

   public static void main(String[] args) throws IOException {
      ServerSocket ss = new ServerSocket(6000);
      Socket s = ss.accept();
      System.out.println("Connected");
      s.close();
      ss.close();
   }
}


On the EV3:

Code: Select all
import java.net.Socket;

public class Client {
   public static void main(String[] args) throws Exception {
      Socket s = new Socket("10.0.1.10", 6000);
      System.out.println("Connected");
      s.close();
   }
}
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm

Re: Bluetooth/USB Data Transfer Issues

Postby gloomyandy » Wed May 14, 2014 11:18 pm

There is no problem with using a PAN in a group situation each student will have a private network between the PC and EV3, they can all use the same 10.0.1.* network without any clashes. A pan is not like using a WifI network where the access point is shared, in effect each EV3 is a separate access point, and has a private network associated with it. Get a couple of PCs and EV3s and try it.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3967
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bluetooth/USB Data Transfer Issues

Postby gloomyandy » Wed May 14, 2014 11:37 pm

As Lawrie has already pointed out the address of the PC from the EV3 will be something like 10.0.1.10, not the address of the PC on your WiFi/classroom network. Note that it may not always be 10.0.1.10, if you connect/disconnect the pan you may end up with different addresses (like 10.0.1.11 etc) being used. So you will need to identify the actual address that has been assigned to the PC. If you don't want to use Bluetooth you can use USB in pretty much the same way, again the EV3 will be on address 10.0.1.1 and again the network will be private and to connect to the PC you will need to use the 10.0.1.* address. Note that in your PC side server program you may have to select the network interface that your code is listening on. I'm not sure if all interfaces are used by default.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3967
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bluetooth/USB Data Transfer Issues

Postby Mark Lanthier » Fri May 16, 2014 3:19 pm

It worked via Bluetooth! Thanks Andy and Lawrie. The address had to be set to "10.0.1.11". I had not realized that the IP address was different when connecting to the PC via the PAN. I have not tried with the USB though. I'll let you know if futher problems arise. I appreciate your help.
Mark Lanthier
New User
 
Posts: 9
Joined: Fri Jan 31, 2014 8:15 pm

Re: Bluetooth/USB Data Transfer Issues

Postby gloomyandy » Fri May 16, 2014 3:28 pm

I would recommend that if you can, you connect from the PC to EV3. The EV3 will always have a fixed IP address (on Bluetooth/USB), the PC may not have. You can also use the leJOS code to discover the address of the EV3 if yoy do this the same code will work on Bluetooth/USB/WiFi. You could use similar mechanisms to allow the EV3 to discover the PC, but we don't provide the code to do that.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3967
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Next

Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff