ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

can't subscribe the message via rosbridge (websocket)

asked 2017-09-30 06:03:50 -0600

sasadasd gravatar image

updated 2017-09-30 06:27:50 -0600


I want to display the turtlesim_node's topic("/turtle1/cmd_vel") by using rosbridge.

to this end, I implement the following 3 codes.


#!/usr/bin/env python
import rospy, os
import SimpleHTTPServer
def kill():
  os.system("kill -KILL " + str(os.getpid()))

os.chdir(os.path.dirname(__file__) + "/../contents")


<!DOCTYPE html>
<meta charset="utf-8" />

<script type="text/javascript" src="">     </script>
<script type="text/javascript" src=""></script>

<script type="text/javascript" type="text/javascript">
  // Connecting to ROS
  // -----------------

  var ros = new ROSLIB.Ros({
     url : 'ws://localhost:9000'

  ros.on('connection', function() {
    console.log('Connected to websocket server.');

  ros.on('error', function(error) {
    console.log('Error connecting to websocket server: ', error);

  ros.on('close', function() {
    console.log('Connection to websocket server closed.');

  // Subscribing to a Topic
  // ----------------------

  var listener = new ROSLIB.Topic({
    ros : ros,
    name :'/turtle1/cmd_vel',
    messageType :'geometry_msgs/Twist'

  listener.subscribe(function(message) {
    console.log('Received message on ' + + ': ' +;;

  <h1>Simple roslib Example</h1>
  <p>Check your Web Console for output.</p>


 <node pkg="webtopic_turtle" name="webserver" type="" args="8000" />
 <include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch"> 
    <arg name="port" value="9000"/>

After that , I executed catkin_make and "chmod +x" in proper directory.

Finally, I executed the following command.

(1)roscore (2)roslanch webtopic_turtle webtopic_turtle.launch (3)open http://localhost:8000/ then the message is appeared in terminal that is executed webtopic_turtle.

[INFO] [WallTime: 1506767932.089070] Rosbridge WebSocket server started on port 9000 - - [30/Sep/2017 19:38:55] "GET / HTTP/1.1" 200 - [INFO] [WallTime: 1506767935.992950] Client connected. 1 clients total. [INFO] [WallTime: 1506767936.406980] [Client 0] Subscribed to /turtle1/cmd_vel

(4) rosrun turtlesim tutlesim_node (5)rosrun turtlesim turtleteleop_key

But, it is not display the message'Received message on …' in terminal that is executed webtopic_turtle. what is the problem ? I confirm the rqt_garph and it showed the diagram that is properly subscribed the message"/turtle1/cmd_vel" in rosbrideg_websocket.

Please let me know if you can find how to resolve the problem. image description

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-10-02 06:43:52 -0600

You say that Received message on is not printed in the terminal.

This is right because you are printing it on the JavaScript console. So in order to see this message, you have to open the Developer Tools on you Web Browser (normally pressing F12) and select the console tab.

edit flag offensive delete link more


Thank you for your advice! I can see the message in my browser.

sasadasd gravatar image sasadasd  ( 2017-10-03 08:09:29 -0600 )edit


Glad to help.

Ruben Alves gravatar image Ruben Alves  ( 2017-10-03 19:55:32 -0600 )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


Asked: 2017-09-30 06:03:50 -0600

Seen: 1,142 times

Last updated: Sep 30 '17