You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The mqtt_client is primarily meant to bridge ROS messages from one ROS system to another ROS system via MQTT. What you are trying to do, however, is bridging messages from ROS to MQTT or from MQTT to ROS.
It's expected that this currently only works for primitive message types. For non-primitive message types such as sensor_msgs/msg/Temperature, the ROS messages are serialized to a binary payload that is then sent via MQTT. This binary payload is not directly human-readable and has to be deserialized by another mqtt_client to then publish as a ROS message on the receiver side.
In your MQTT to ROS test, you have actually come up with the right question: "I actually have no idea how to format the MQTT publisher message?". In principle, you can always come up with a JSON representation of any ROS message, so why not send JSON equivalents of the ROS messages via MQTT? Although this would most likely increase the payload size, it's could definitely be a very helpful feature for the mqtt_client, see #9!
As of today, this feature is not yet available on the main branch. There is, however, a pull request #51 that implements this feature. Please refer to the PR discussion on how to use it and why it hasn't been merged yet.
Hello,
I have tested this repo with primitive types and everything works as expected.
I can't get it to work with non primitive type, however.
Test 1 - ROS2 to MQTT
Terminal 1:
ros2 launch mqtt_client standalone.launch.ros2.xml
[mqtt_client-1] [INFO] [1722803980.839742950] [mqtt_client]: Connected to broker at 'tcp://localhost:1883' [mqtt_client-1] [INFO] [1722803980.839865437] [mqtt_client]: Subscribed MQTT topic 'mqtt_client/ros_msg_type/pingpong/ros' [mqtt_client-1] [INFO] [1722804034.407838293] [mqtt_client]: Subscribed ROS topic '/ping/ros' of type 'sensor_msgs/msg/Temperature'
Terminal 2:
>> ros2 topic pub /ping/ros sensor_msgs/msg/Temperature "{temperature: 100.5}" --once
publisher: beginning loop publishing #1: sensor_msgs.msg.Temperature(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=0, nanosec=0), frame_id=''), temperature=100.5, variance=0.0)
Terminal 3:
>> mosquitto_sub -h localhost -t "pingpong/ros"
Y@
Maybe an encoding issue?
Test 2 - MQTT to ROS
Terminal 1: same
Terminal 2:
>> ros2 topic echo /pong/ros
1722804779.802696 [0] recvUC: malformed packet received from vendor 1.16 state parse:HEARTBEAT <52545053 02010110 1af91001 f3542884 37bb9341 0e010c00 01100b74 60cc4736 @0x50 07011c00 00000804 00001b03 00000000 07000000 00000000 07000000 2e000000> (note: maybe partially bswap'd) smid 0x7 flags 0x1 otnh 28 rid 0x4080000 wid 0x31b0000 first 7 last 7
Terminal 3:
>> mosquitto_pub -h localhost -t "pingpong/ros" -m 100.5
I actually have no idea how to format the MQTT publisher message?
This is most likely user error but I'm not sure how to make this work.
Thank you in advance for any help.
The text was updated successfully, but these errors were encountered: