The mqtt_client package provides a ROS Nodelet or ROS 2 component node that enables connected ROS-based devices or robots to use the MQTT protocol to exchange ROS messages through an
MQTT broker. This generally applies to any ROS message type. mqtt_client can also exchange raw messages with MQTT clients running on non-ROS-based devices.
Source code address:
https://github.com/ika-rwth-aachen/mqtt_client
Install
sudo apt update
安装mqtt-client 语句
sudo apt install ros-$ROS_DISTRO-mqtt-client
$ROS_DISTRO is your ros version number
sudo apt install ros-humble-mqtt-client
Modify configuration file
cd /opt/ros/humble/share/mqtt_client/config
vim params.ros2.yaml
Change it to your own address
start up
ros2 launch mqtt_client standalone.launch.ros2.xml
Start successfully
Test:
Publish messages on ros side
ros2 topic pub /ping/ros std_msgs/msg/String "{data: \"Hello MQTT\"}"
Local computer client listening