Ask Your Question
2

Multiple TCP connections using rosserial_server with WiFi Arduino

asked 2017-10-26 04:50:06 -0500

Andy West gravatar image

updated 2017-10-26 14:30:31 -0500

Dear all,

I am currently running an Arduino Uno* with an ATWINC1500 WiFi breakout from Adafruit and can successfully publish topics over WiFi to a master using rosrun rosserial_python serial_node.py tcp. This has been achieved using code modified from this previous ROS answer supplied by @ahendrix.

The trouble I run into is running two of these devices at the same time. They both have unique IP addresses and are connected to the network, running differently named topics, and individually can be successfully connected and publish topics.

The first device can be connected using rosrun rosserial_python serial_node.py tcp. Simply starting a second device does not lead to be being connected. If I run a second serial_node.py with a different node name to avoid conflicts (by using rosrun rosserial_python serial_node.py tcp __name:=OtherNodeName), I get an error "socket.error: [Errno 98] Address already in use".

As the socket can't be given as an argument to serial_node.py, I tried using rosrun rosserial_server socket_node as rosserial_server in theory can handle multiple connections. Using default port 11411, I find the node displays:

Listening for rosserial TCP connection on port 11411 but never finds any devices, unlike rosserial_python serial_node.py which was successful.

Am I missing something for rosserial_server to be able to identify and connect to these devices?

Is there another way of connecting multiple TCP devices such as these arduinos with wifi simultaneously?

Thank you for your time,

Andy


UPDATE:

Having followed some very good advice from gvdhoorn, I investigated the packet traffic using Wireshark. Turns out for rosserial_server socket_node the connection between the arduino and the master must not complete (there are a few messages back and forth, but finishes before the "normal" regular published traffic commences as seen when using rosserial_python serial_node.py tcp).

By adding a short delay after nh.advertise(), the master and the arduino are able to make a connection (though socket_node reports some errors to begin with), and start publishing. This also allows for multiple arduinos to be connected! However, the connection then drops out after a minute or so from what I observe as TCP out-of-order issues.

I thought this might be because of the delay(1000) in the main loop, so I replaced this instead for using millis() and letting nh.spinonce() not get held up. This didn't improve the situation, it in fact might have made the drop out occur earlier, but I haven't done any actual timings to confirm that.

There are occurrences of TCP out-of-order when using serial_node.py, but they seem to resolve themselves very quickly and not terminate the connection between the arduino and the master when using identical code. I left this running for a few hours with no termination of connection.

Better questions:

What is it about socket_node that leads to traffic being treated differently compared to serial_node.py and lead to the connection being terminated?

What could be done to improve the stability of TCP connections when using rosserial_server socket_node ... (more)

edit retag flag offensive close merge delete

Comments

I'm not a rosserial expert, but just to get a feeling for what is going on at the network level, I'd run Wireshark while trying to get things to connect. That should at least tell you whether your clients are trying to connect, how, where and in what way. It should also show server activity.

gvdhoorn gravatar imagegvdhoorn ( 2017-10-26 05:08:48 -0500 )edit

Note that using TCP/IP over a wireless link is not a very good choice for anything interactive. Whenever I used rosserial over wireless I've used the UDP variant. Trouble is though that it currently lacks some of the functionality that the TCP implementation does have.

gvdhoorn gravatar imagegvdhoorn ( 2017-10-26 05:09:56 -0500 )edit

I've investigated using Wireshark. For rosserial_python serial_node.py it appears to run nicely, however for rosserial_server socket_node there are some errors being thrown around. By adding delay(100); just after nh.advertise(); the arduinos manage to connect! But dropout randomly later.

Andy West gravatar imageAndy West ( 2017-10-26 08:53:04 -0500 )edit

The "socket.error: [Errno 98] Address already in use" suggest that both copies of serial_node.py are trying to listen on the same port number. I'm not sure if a single node is designed to handle multiple clients or not, you might want to look for documentation about this.

ahendrix gravatar imageahendrix ( 2017-10-27 21:45:07 -0500 )edit

If a single node is supposed to handle multiple clients, then this behavior is a bug. Otherwise you may want to try running the second node and its Arduino on a different port number.

ahendrix gravatar imageahendrix ( 2017-10-27 21:46:36 -0500 )edit

(Failing to handle multiple clients is still probably a bug for most software that has a listening socket, but if the docs don't say it's supported you may have a hard time getting this "bug" fixed unless you're willing to submit the fix yourself)

ahendrix gravatar imageahendrix ( 2017-10-27 21:47:08 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-10-31 08:56:25 -0500

Andy West gravatar image

The result of this investigation is that it may have been an intermittent bug. Having reinstalled rosserial_server just to be pedantic in checking everything, the continual dropping out of devices using rosserial_server socket.launch has be greatly reduced (drop out ~ 1 per hour compared to ~1 per minute).

The rosserial_server socket_node will accept multiple clients successfully as it should (unlike serial_node.py as ahendrix points out).

The only advice I can offer to others is to include a reconnect function as mentioned in the question. As rosserial_server is in development, if I can track down where this bug might of occurred, I will report it.

Thank you all for your help.

edit flag offensive delete link more

Comments

1

I don't know how much this applies to your problem but I use multiple rosserial_server nodes instead (one for each client) by adding args="_port:=11412", etc. to the .launch file.

prnthp gravatar imageprnthp ( 2017-11-05 14:08:02 -0500 )edit
1

That's a useful tip! Never though of setting separate ports to allow for separate nodes when using rosserial_server. Thanks prnthp.

Andy West gravatar imageAndy West ( 2017-11-05 14:34:17 -0500 )edit

can you guys elaborate how to do this port modification? can i make the port number arguments changable and connect to several ports like that? please guide

ELLEO gravatar imageELLEO ( 2018-02-22 20:05:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-10-26 04:50:06 -0500

Seen: 1,370 times

Last updated: Oct 31 '17