ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

wrong network adapter with InetAddressFactory.newNonLoopback()

asked 2012-10-08 03:43:46 -0500

bajo gravatar image

Hi,

the last days i tried to run android_tutorial_pubsub and ran into several problems.

First i had the problem that

NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate();

was executed, which won't let you connect from a different device.

So i changed it into something like NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress());

This gives you the first network device which is not a loopback device, but it does not check what device it is. For me it gave me vsnet0 instead of wlan0. So whenever i tried to connect to the subscribed topics or only executed rostopic info /chatter it would complain about not being able to connect. This is somehow expected as the ip address of vsnet0 is not in the same subnet as wlan0 and my other computers which run ROS.

I have now hardcoded the ip address for wlan0 from my android phone, but this is only usefull for my development environment, as i can't expect to have the same ip at other places.

The question now is how can i select the network device i want to use instead of just getting the first nonLoopback device?

Any idea or advice would be helpfull. Thank you.

Greetings, Markus

edit retag flag offensive close merge delete

Comments

Maybe that's a bug in rosjava. Consider filing a ticket on the corresponding bug tracker. To come up with a workaround, I suggest you have a look at the source code of InetAddressFactory: http://mediabox.grasp.upenn.edu/roswiki/doc/api/rosjava/html/InetAddressFactory_8java_source.html

Lorenz gravatar image Lorenz  ( 2012-10-08 04:12:58 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2012-10-10 04:05:40 -0500

bajo gravatar image

Hi, thank you both for your hints.

I managed to get the desired effect by changing the function newNonLoopback() so that it won't return PointToPoint interfaces like my phones radio network adapter vsnet0.

rosjava_core/rosjava/src/main/java/org/ros/address/InetAddressFactory.java


public static InetAddress newNonLoopback() {
  for (InetAddress address : getAllInetAddresses()) {
    // IPv4 only for now.
    boolean p2p;
    try {
       p2p = NetworkInterface.getByInetAddress(address).isPointToPoint();
    } catch (SocketException e) {
      throw new RosRuntimeException(e);
    }   
    if (!address.isLoopbackAddress() && isIpv4(address) && (!p2p)) {
      return address;
    }   
  }   
  throw new RosRuntimeException("No non-loopback interface found.");
}

I will ask the maintainer of rosjava if he thinks it is wise to include in his repository so others can use it too.

edit flag offensive delete link more

Comments

Nice work. Best if you add a patch to the ticket that was referenced in @ahendrix answer or create a ticket on rosjava.googlecode.com with a patch attached.

Lorenz gravatar image Lorenz  ( 2012-10-10 04:11:30 -0500 )edit

Please post issues to the rosjava issues list (http://code.google.com/p/rosjava/issues/list). I don't follow the trac tickets @ahendrix mentioned.

damonkohler gravatar image damonkohler  ( 2012-10-10 05:23:16 -0500 )edit

I opened a ticket at http://code.google.com/p/rosjava/issues/list as this seems the correct place for it.

bajo gravatar image bajo  ( 2012-10-12 09:12:39 -0500 )edit
2

answered 2012-10-08 09:48:34 -0500

ahendrix gravatar image

This is a known bug: https://kforge.ros.org/appmanandroid/trac/ticket/26

I don't know why it's assigned to me. I don't think anyone is currently working on it.

edit flag offensive delete link more

Comments

I opened a ticket at http://code.google.com/p/rosjava/issues/list as this seems the correct place for it.

bajo gravatar image bajo  ( 2012-10-12 09:13:36 -0500 )edit
0

answered 2014-05-15 15:06:19 -0500

Daniel Stonier gravatar image

There is I think a better way to tackle this - usually you have the URI of the ros master you want to connect to, so if you can successfully open a socket to that, it means you can introspect what network interface the socket connection is routing along. You can read this issue thread for more details along with some test code I use to solve the multiple network interface problem on android devices.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-10-08 03:43:46 -0500

Seen: 717 times

Last updated: May 15 '14