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

mqtt_client doesn't create generic publisher at runtime change of message type #45

Open
vishantyadav-eic opened this issue Dec 8, 2023 · 1 comment

Comments

@vishantyadav-eic
Copy link

when we change the message type at runtime no logs are seen from mqtt_client node, after restart the client it throws an error: "[mqtt_client-1] [ERROR] [1702010603.069871187] [mqtt_client]: Failed to create generic subscriber: could not create subscription: invalid allocator, at ./src/rcl/subscription.c:218"
After restarting the mqtt_client again it works successfully but the issue is I have to restart mqtt_client twice.
ROS Distro: humble, using Docker

we want to change the message at runtime without restarting the mqtt_client , How we can achieve the same ?

@lreiher
Copy link
Member

lreiher commented Jan 8, 2024

I can reproduce the issue. In my case, the mqtt_client errors as soon as the message type changes, no restart needed.

ros2 launch mqtt_client standalone.launch.ros2.xml
# ---
ros2 topic pub /ping/ros std_msgs/msg/String "{data: \"Hello MQTT\"}"
# ---
ros2 topic pub /ping/ros std_msgs/msg/Int32 "{data: 42}"
[INFO] [launch]: All log files can be found below /home/dockeruser/.ros/log/2024-01-08-23-32-51-683641-I2200044-linux-1
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [mqtt_client-1]: process started with pid [78]
[mqtt_client-1] [WARN] [1704753171.855153747] [mqtt_client]: Parameter 'broker.tls.enabled' not set, defaulting to '0'
[mqtt_client-1] [WARN] [1704753171.855233754] [mqtt_client]: Parameter 'client.id' not set, defaulting to ''
[mqtt_client-1] [WARN] [1704753171.855244754] [mqtt_client]: Client buffer can not be enabled when client ID is empty
[mqtt_client-1] [WARN] [1704753171.855253483] [mqtt_client]: Parameter 'client.clean_session' not set, defaulting to '1'
[mqtt_client-1] [WARN] [1704753171.855268283] [mqtt_client]: Parameter 'client.keep_alive_interval' not set, defaulting to '60.000000'
[mqtt_client-1] [WARN] [1704753171.855276323] [mqtt_client]: Parameter 'client.max_inflight' not set, defaulting to '65535'
[mqtt_client-1] [INFO] [1704753171.855294562] [mqtt_client]: Bridging ROS topic '/ping/ros' to MQTT topic 'pingpong/ros'
[mqtt_client-1] [INFO] [1704753171.855314551] [mqtt_client]: Bridging MQTT topic 'pingpong/ros' to ROS topic '/pong/ros'
[mqtt_client-1] [INFO] [1704753171.856069647] [mqtt_client]: Connecting to broker at 'tcp://localhost:1883' ...
[mqtt_client-1] [INFO] [1704753171.856856371] [mqtt_client]: Connected to broker at 'tcp://localhost:1883'
[mqtt_client-1] [INFO] [1704753171.856943619] [mqtt_client]: Subscribed MQTT topic 'mqtt_client/ros_msg_type/pingpong/ros'
[mqtt_client-1] [INFO] [1704753200.867931836] [mqtt_client]: Subscribed ROS topic '/ping/ros' of type 'std_msgs/msg/String'
[mqtt_client-1] [INFO] [1704753201.363448881] [mqtt_client]: ROS publisher message type on topic '/pong/ros' set to 'std_msgs/msg/String'
[mqtt_client-1]
[mqtt_client-1] >>> [rcutils|error_handling.c:108] rcutils_set_error_state()
[mqtt_client-1] This error state is being overwritten:
[mqtt_client-1]
[mqtt_client-1]   'create_subscription() called for existing topic name rt/ping/ros with incompatible type std_msgs::msg::dds_::Int32_, at ./src/subscription.cpp:146, at ./src/rcl/subscription.c:108'
[mqtt_client-1]
[mqtt_client-1] with this new error message:
[mqtt_client-1]
[mqtt_client-1]   'invalid allocator, at ./src/rcl/subscription.c:218'
[mqtt_client-1]
[mqtt_client-1] rcutils_reset_error() should be called after error handling to avoid this.
[mqtt_client-1] <<<
[mqtt_client-1] invalid allocator, at ./src/rcl/subscription.c:218
[mqtt_client-1] [ERROR] [1704753223.868018734] [mqtt_client]: Failed to create generic subscriber: could not create subscription: invalid allocator, at ./src/rcl/subscription.c:218

I'm afraid that switching the message type is currently not supported in ROS 2. Feel free to open a pull request if you decide to fix the issue in source code yourself.

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

No branches or pull requests

2 participants