ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Publishing to ROS node running on different Computer

asked 2022-11-07 20:08:15 -0600

akumar3.1428 gravatar image

updated 2022-11-07 20:56:52 -0600

ravijoshi gravatar image

I would like to know how I can send data to different computer, I initiated with sending data into the same machine using the code. However, getting the following error message, is there a specific way on entering the IP address or any other requirement that needs to be taken care of before starting sending the message. Like do I need to install rosbridge and run it before sending the message.

Error

[roslibrust::rosbridge::client] Failed to reconnect: CommFailure(Io(Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }))

CODE

use log::*;
use roslibrust::ClientHandle;

roslibrust_codegen_macro::find_and_generate_ros_messages!("assets/ros1_common_interfaces/std_msgs");

/// This example creates a client, and publishes a message to the topic "talker"
/// Running this example at the same time as subscribe_and_log will have the two examples
/// pass messages between each other.
/// To run this example a rosbridge websocket server should be running at the deafult port (9090).
#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    simple_logger::SimpleLogger::new()
        .with_level(log::LevelFilter::Debug)
        .without_timestamps() // required for running wsl2
        .init()
        .unwrap();

    let client = ClientHandle::new("ws://localhost:9080").await?;
    let publisher = client.advertise::<std_msgs::Header>("talker").await?;

    loop {
        let msg = std_msgs::Header::default();
        info!("About to publish");
        publisher.publish(msg).await.unwrap();
        info!("Published msg...");
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    }
}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-11-08 15:31:39 -0600

akumar3.1428 gravatar image

I figure out that It is essential to run rosbridge on the computer where you want to send data to. After installing rosbridge using the following command sudo apt-get install ros-<rosdistro>-rosbridge-server and launching using the command roslaunch rosbridge_server rosbridge_websocket.launch it was working perfectly. I would like to suggest to take care of the port number as rosbridge usually use 9090 and any different port number in the code could lead to error.

I am closing this issue as it has been solved. If the problem persists, please comment and the issue will be reopened if appropriate.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2022-11-07 20:08:15 -0600

Seen: 31 times

Last updated: Nov 08 '22