Cannot connect rosbridge by other devices
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 rosbridgeserver, and create a webserver using apache, I open my web interface on browser of my PC, node rosbridgewebsocket 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.
Asked by sagittarius_silver on 2020-10-24 19:18:55 UTC
Answers
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
Asked by ChriMo on 2020-10-30 19:08:35 UTC
Comments
Thanks for your guidance. I followed and my package worked fine. Thank you very much!
Asked by sagittarius_silver on 2020-11-15 06:55:44 UTC
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?
Asked by hyebin on 2021-10-29 00:48:11 UTC
Comments