This issue arises because the subscriber cannot resolve the URI of the publisher. When a ROS node advertises a topic, it provides a hostname:port combination (a URI) that other nodes use to establish contact when they want to subscribe to that topic. It is important that the hostname the publishing node provides can be used by all other nodes to contact it. The ROS client libraries use the name reported by the machine as hostname. This is the name that is returned by the Linux command “hostname”. If a machine reports a hostname that is not addressable by other machines, you need to set either the ROS_IP or ROS_HOSTNAME environment variables. (Reference: http://wiki.ros.org/ROS/NetworkSetup) ROS_IP and ROS_HOSTNAME are optional environment variables that set the declared network address of a ROS Node or tool. They are mutually exclusive; if both are set, ROS_HOSTNAME will take precedence. Use ROS_IP if you are specifying an IP address and ROS_HOSTNAME if you are specifying a name. (Reference: http://wiki.ros.org/ROS/EnvironmentVariables)
The environment variable ROS_MASTER_URI is required when the ROS core is not running on localhost. ROS_MASTER_URI are used by ROS nodes to locate the master.
TO RESOLVE THIS ISSUE, ALWAYS SPECIFY ROS_IP BEFORE STARTING A NODE ON LINUX. Use the IP address of the network interface on which the node is communicating with the ROS network.
To ensure the correct behavior of the MATLAB ROS support package, it is recommended that you always specify ROS_IP and ROS_MASTER_URI explicitly.
For example, if the ROS core is running on a machine with IP: 192.168.198.128 and MATLAB is running on a machine with IP: 192.168.198.1, then we should set up the environment variables as follows (please replace the IP addresses below with the IP addresses of your network setup):
In Linux terminal:
$ export ROS_IP=192.168.198.128
$ export ROS_MASTER_URI=http://192.168.198.128:11311
$ start a roscore, publisher or subscriber
To make the above change permanent, put the above two export commands in the “.bashrc” file, as follows,
At the end of the file “.bashrc”, add the two export statements.
Restart Linux terminal.