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

Cannot connect rosbridge by other devices

asked 2020-10-24 19:18:55 -0500

sagittarius_silver gravatar image

Hi everyone, I'm trying to send a message using a web interface. Below is the section that connects my rosbridge_server

var ros = new ROSLIB.Ros({
    url : 'ws://localhost:9090'
});

ros.on('connection', function() {
    document.getElementById("status").innerHTML = "Connected";
});

ros.on('error', function(error) {
    document.getElementById("status").innerHTML = "Error";
});

ros.on('close', function() {
document.getElementById("status").innerHTML = "Closed";
});

// Publishing a Topic

var test_button = new ROSLIB.Topic({
ros : ros,
name : "/button",
messageType : 'std_msgs/Byte'
});

function display1() {
var txt = new ROSLIB.Message({
    data: 1
});
test_button.publish(txt);
}

After run rosbridge_server, and create a webserver using apache, I open my web interface on browser of my PC, node rosbridge_websocket announces client connected successfuly.
But when I use my smartphone, or other PC, I can still open my web interface, but rosbridge has no response. I have tried on both ros kinetic and melodic.
Can anyone show me the solution? Sorry for my bad English.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-10-30 19:08:35 -0500

ChriMo gravatar image

Hi, this is a typical example pitfall ;-(

Please check this: url : 'ws://localhost:9090'

This will work only, when you are working from localhost

When connecting from other remote devices you need to connect to the websocketserver address....

Easy solution:

Install a small webserver at your robot or the device where the websocketserver is running and use something like this at your javascript script:

var ip = location.host; var ros = new ROSLIB.Ros({ url: 'ws://' + ip + ':9090' });

Works now out-of-the-box from any browser with websocket support

Have fun

Cheers

Chrimo

edit flag offensive delete link more

Comments

Thanks for your guidance. I followed and my package worked fine. Thank you very much!

sagittarius_silver gravatar image sagittarius_silver  ( 2020-11-15 05:55:44 -0500 )edit

hi. i have same issue. how to solve it? first, "python3 -m http.server 8080" seconde, "roslaunch rosbridge_server rosbridge_websocket.launch" and in another computer(differenct ip), i also open web interface, but no response rosbridge. my location.host is "aaa.aaa.aaa.aaa", and another computer's ip is (bbb.bbb.bbb.bbb) i followed guide, but didn't work. how to solve that problem?

hyebin gravatar image hyebin  ( 2021-10-29 00:48:11 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-10-24 19:18:55 -0500

Seen: 1,171 times

Last updated: Oct 30 '20