Example of creating an MQTT server with publisher in ROS Noetic and python subscriber
You must have
- Docker
- Docker-compose
Clone the repository and navigate to the root folder
sudo -E docker-compose up
Note that the -E
option is what enables passing environment variables from the host machine to the container.
If you wish to force re-building of the docker images
sudo -E docker-compose up --build
The docker-compose should now spin up three containers.
- mqtt_broker
- The MQTT server which relays messages. This is based on VerneMQ.
- mqtt_publisher
- A ROS Noetic network spinning up a publisher which publishes dummy data to the broker at 1 Hz. The communication on the ROS network is relayed to the MQTT broker through an mqtt_bridge.
- mqtt_subscriber
- Subscriber written in Python which uses the paho mqtt client.
The publisher will print its published message while the subscriber will echo the message.
The VerneMQ status interface is exposed in localhost and may be accessed at
http://localhost:8888/status
Each container may be accessed after startup through the following command
sudo docker exec -it <container_name> /bin/bash
Note that the example currently has anonymous access enabled by default!
A user exists with the following credentials for the sake of the example
- Username: test_user
- Password: test_password
To manage the user/password file see the official VerneMQ documentation.
To inspect the broker during runtime you may use docker exec
to access the container and use the vmq-admin
tool to
inspect the broker. See the VerneMq documentation for more details.
Thanks to The EIT-hub experiments repository for heplful guide to VerneMQ.