ika-rwth-aachen / mqtt_client

ROS / ROS 2 C++ Node for bi-directionally bridging messages between ROS and MQTT
MIT License
182 stars 41 forks source link

How can I publish same ROS topic on multiple MQTT messages? #18

Open Lakshay011 opened 1 year ago

Lakshay011 commented 1 year ago

We attempted to publish a ROS topic message on multiple MQTT topics, but only one of the topics received the message. Is there a way to publish a single ROS message to multiple MQTT topics?

Config File:

broker:
    host: localhost
    port: 1883
bridge:
    ros2mqtt:
        -ros_topic: /agv/scan
         mqtt_topic: agv_mqtt/scan/ros1
         -ros_topic: /agv/scan
         mqtt_topic: agv_mqtt/scan/ros2
        -ros_topic: /agv/scan
         mqtt_topic: agv_mqtt/scan/primitive/ros1
         primitive: true
lreiher commented 1 year ago

Hi, sorry for the delayed response.

What you are reporting is actually expected behavior. We are storing the ROS subscribers in a map structure, such that we can only store one ros2mqtt connection per ROS topic (see this line of code).

I guess we could change this behavior or at least issue a warning, but first, could you please describe why you would want to publish the same data to multiple topics?

Lakshay011 commented 1 year ago

Apologies for the delay in getting back to you.

We currently have a situation where we need to transmit Lidar data to both a ROS-based environment and a web-based environment for visualization. The ROS-based environment is capable of decoding non-primitive data, whereas the web-based environment lacks a decoding library that can convert this data into a ROS object. Therefore, our aim is to send the Lidar data as primitive data to enable easy decoding.

If you are aware of any library that can assist us in decoding non-primitive messages into ROS object on the web side, please inform us.

lreiher commented 1 year ago

For the web based interpretation, it would probably help a lot if we had https://github.com/ika-rwth-aachen/mqtt_client/issues/9, unfortunately that's an open issue at the moment.

For the other issue, that we cannot publish the same ROS topic to multiple MQTT topics, you would have two options at the moment: