Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Send messages as JSON to generic MQTT clients #9

Open
Pedroacsilva opened this issue Nov 10, 2022 · 6 comments · May be fixed by #51
Open

[Feature Request] Send messages as JSON to generic MQTT clients #9

Pedroacsilva opened this issue Nov 10, 2022 · 6 comments · May be fixed by #51

Comments

@Pedroacsilva
Copy link

Hello,

First of all, I'd like to thank you for publishing this, it's been very useful.

I'm interested in transmitting ROS messages typed sensor_msgs/JointStates to a broker outside of the ROS environment. As is, my MQTT subscriber, outside of the ROS environments, receives mostly gibberish. I presume this is because primitives messages do not support messages typed sensor_msgs. Are there any plans to support these?

@lreiher
Copy link
Member

lreiher commented Nov 14, 2022

Hi, happy that you are using the mqtt_client!

You are right, the primitive message support only covers the primitives (int, float, bool, ...) from std_msgs. What is happening in your case is that the sending mqtt_client serializes the sensor_msgs/JointStates message, but your receiving client apparently has no way of deserializing the incoming data.

I'm wondering how the target state would look like to you? Receiving a stringified JSON of the message?

@Pedroacsilva
Copy link
Author

Hello, thank you for the quick reply!

Yes, my goal is to receive messages in a JSON string, ideally. Right now, my MQTT client (Mosquitto) receives essentially gibberish and I presumed it was due to /JointStates not being a primitive message type (after reading some more, I don't believe that was the reason).

Is there support for mqtt_client to de/serialize ROS messages as JSON strings?

@lreiher
Copy link
Member

lreiher commented Nov 15, 2022

There is no support of such functionality as of now.

Unfortunately, it's not that easy to do from C++, without having access to proper type introspection at runtime. Python would be easy for this (and could also simply use rosbridge_suite).

ros_msg_parser could potentially help to implement such a feature in our C++ node. We are already using a topic_tools::ShapeShifter to subscribe to generic message types. I would also like to try this out, but cannot yet guarantee that I will be getting to this anytime soon.

@lreiher lreiher changed the title [Feature Request] sensor_msgs/JointState [Feature Request] Send messages as JSON to generic MQTT clients Nov 15, 2022
@Pedroacsilva
Copy link
Author

I'll look into these topics in order to implement this functionality. Thank you for your assistance and I'd like to apologize for not being very clear in my request -- clearly I didn't have a solid grasp on ROS-MQTT communications.

@lreiher
Copy link
Member

lreiher commented Nov 15, 2022

Nothing to apologize for! Feel free to open a pull request if you get this implemented in the mqtt_client!

@lreiher
Copy link
Member

lreiher commented Feb 12, 2023

This function could be used:

https://github.com/facontidavide/ros_msg_parser/blob/f874a6f98e0d1ed72e6d23f3671d26ed96a49986/include/ros_msg_parser/ros_parser.hpp#L160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants