Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
ros2 pub/sub custom message through ros2-web-bridge to client app

I want to publish ros2 custom message through ros2-web-bridge to react app. In react i have subscribed to published custom message. ros2-web-bridge is running on port ws://localhost:9090. I have created the custom message interface on ros2.

   // this is client side web app subscribe method
   var example = new ROSLIB.Topic({
  ros: ros,
  name: "/sample",
  messageType: `tutorial_interfaces/msg/Num`,
});

// Subscribe a Topic
example.subscribe(function (message) {
  console.log("Subscribe data", message);
});


// This is ros2 publish python code
import rclpy
from rclpy.node import Node
from tutorial_interfaces.msg import Num    # CHANGE
class MinimalPublisher(Node):

def __init__(self):
    super().__init__('minimal_publisher')
    self.publisher_ = self.create_publisher(Num, 'sample', 10)     # CHANGE
    timer_period = 0.5
    self.timer = self.create_timer(timer_period, self.timer_callback)
    self.i = 0

// This is ros2 published class and method
def timer_callback(self):
    msg = Num()                                           # CHANGE
    msg.num = self.i                                      # CHANGE
    self.publisher_.publish(msg)
    self.get_logger().info('Publishing: "%d"' % msg.num)  # CHANGE
    self.i += 1
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you already have a custom message created and subscribed to on the React side all you have to do here is include the message header and it'll work just like a std_msg. Ex: if you have package custom_interface that includes a custom message type my_msg your code would look something like this:

// This is ros2 publish python code
import rclpy
from rclpy.node import Node
from custom_interface.msg import my_msg
class MinimalPublisher(Node):

def __init__(self):
    super().__init__('minimal_publisher')
    self.publisher_ = self.create_publisher(my_msg, 'sample', 10)
    timer_period = 0.5
    self.timer = self.create_timer(timer_period, self.timer_callback)
    self.i = 0

// This is ros2 published class and method
def timer_callback(self):
    msg = my_msg()
    my_msg.custom_field = self.i
    self.publisher_.publish(my_msg)
    self.get_logger().info('Publishing: "%d"' % my_msg.custom_field)
    self.i += 1

If the web-bridge is already setup like you say, that will all work.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!