These instructions will work on any Debian based OS including Ubuntu, RaspberryPi, WSL2 etc...
(For non-Debian distros, commands for installation need to be tweaked)
By default the config allows only to use local connections for security reasons but since authentication is enabled below, that's not the case.
Latest instructions are here on docker website.
You can also use this script - install-docker.sh
cd mqtt5broker
touch config/pwfile
# In case you don't have docker-compose you can install it
sudo apt install docker-compose
# Run the docker container for mqtt
sudo docker-compose -p mqtt5broker up -d
sudo docker ps
# login interactively into the mqtt container
sudo docker exec -it <container-id> sh
# add user and it will prompt for password
mosquitto_passwd -c /mosquitto/config/pwfile <yourID>
# delete user command format
mosquitto_passwd -D /mosquitto/config/pwfile <user-name-to-delete>
# type 'exit' to exit out of docker container prompt
Then restart the container
sudo docker restart <container-id>
sudo apt install mosquitto-clients
# Without authentication
mosquitto_sub -v -t 'hello/topic'
# With authentication
mosquitto_sub -v -t 'hello/topic' -u <yourID> -P <password>
# Without authentication
mosquitto_pub -t 'hello/topic' -m 'hello MQTT'
# With authentication
mosquitto_pub -t 'hello/topic' -m 'hello MQTT' -u <yourID> -P <password>
Read more about it here => https://mqttx.app/
sudo docker run -d --name mqttx-web -p 80:80 emqx/mqttx-web
We publish simulated temperature, humidity and light sensor data. And we subscribe topics to receive commands to control lamp1, lamp2, lamp3.
# install paho-mqtt to communicate with MQTT broker
pip install paho-mqtt
# run IoTNode.py
python IoTNode.py
Github => https://github.com/eclipse/mosquitto