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

Is there a way to determine IP address of publisher for each message

asked 2017-11-21 04:22:04 -0500

Creed gravatar image


I'm currently developing small system for monitoring and management of a mobile robot group in ROS. One of system's features is reservation mechanism, which lets students reserve exclusive access to the robot - reserved robot only reacts to commands coming from that computer. I want to base it on IP addresses of computers in laboratory.

Here comes my question: Is there a (ROS-based) way to determine IP address of publisher for each message coming to the robots from computers in the laboratory?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-11-21 07:22:56 -0500

updated 2017-11-21 11:51:48 -0500


Maybe I found a solution, not the pretiest, not the easiest, but it may work (but it's cpp only) :

  1. You can find the IP of a ROS node by contacting the master (rosnode info my_node will return the ip of the node, with many other information)

  2. According to The connection header documentation, the node currently sending data can be found in the connection header.

  3. You can use Message event to get the connection header.

  4. To manipulate Message event, you can check Passthrough Filter, just adapt the code to not let the message go through unless the IP is OK. Also check the message filter documentation.

The 3. and 4. are optional, if you can manage to get the connection header by an another way, or the message event by an another way.

It may be easier in Python but i'm not experimented enough in python to help.

Edit from Creed comment :

In CPP, use the cpp publisher tutorial / 2.4 MessageEvent to get message event.

for python check Creed's comment below

edit flag offensive delete link more



Thank you for directing me to the solution.

So finally I came up with this (based on simple publisher/subscriber tutorial):

def callback(data):
    callerid = data._connection_header['callerid']
    master = rosgraph.Master('listener')
    ip = master.lookupNode(callerid)
Creed gravatar image Creed  ( 2017-11-21 11:34:02 -0500 )edit

Nice, it's indeed easier in python, thanks for the python code :)

lmathieu gravatar image lmathieu  ( 2017-11-21 11:53:39 -0500 )edit

answered 2017-11-21 05:13:29 -0500

IvanV gravatar image

I don't think that feature comes out of the box in ROS. You can always use custom messages or encapsulated messages with an "ip" or "source" field on them to identify the sender.

edit flag offensive delete link more


Use of custom messages is something what came to my mind, but i would like to avoid it, because it forces me to modify already existing code used to steer the robots.

Creed gravatar image Creed  ( 2017-11-21 05:26:32 -0500 )edit

As far as i know, roscore collects ip at least at the moment of first message coming on given topic. So i was wondering if that info is somehow available to gather on low level of ROS (maybe in ros_comm stack?)

Creed gravatar image Creed  ( 2017-11-21 05:28:02 -0500 )edit

You don't actually need to modify current steering node. You can just put a "filtering node" in the middle that reads custom topics and publishes back to steering node only the relevant/de-capsulated ones.

IvanV gravatar image IvanV  ( 2017-11-21 05:34:41 -0500 )edit

On the robot-side it may be good idea for workaround, but still i would have to modify Python wrapper for existing RosAria library, which in fact ends up in rewriting (of course only partially) almost whole code.

Creed gravatar image Creed  ( 2017-11-21 05:57:02 -0500 )edit

Question Tools


Asked: 2017-11-21 04:22:04 -0500

Seen: 2,611 times

Last updated: Nov 21 '17