This repository contains an MQTT broker for an IoT fleet management software. The MQTT broker facilitates communication between IoT devices and the fleet management system.
-
Create a
passwdfile within theconfigfolder. This file will store the authentication credentials for accessing the MQTT broker. Formatted like this:user:password -
Build the
mqtt-brokerDocker image using the provided Dockerfile:docker build -t mqtt-broker . -
Start the services using Docker Compose:
docker-compose up --build
To publish messages to the MQTT broker, you can use the following command:
docker-compose run mqtt-pub sh -c "mosquitto_pub -h mqtt-broker -t test -m 'Hello World' -u admin -P password"To change the authentication password:
docker-compose exec mqtt-broker mosquitto_passwd -b /mosquitto/config/passwd admin NEWPASSWORDAfter a password change, the MQTT broker needs to be restarted.
docker-compose restart mqtt-brokerNow run the pub/sub services with the new password
docker-compose run mqtt-sub sh -c "mosquitto_sub -h mqtt-broker -t test -u admin -P CHANGED_PASSWORD"docker-compose run mqtt-pub sh -c "mosquitto_pub -h mqtt-broker -t test -m 'Hello World' -u admin -P CHANGED_PASSWORD"Make sure to replace NEWPASSWORD and CHANGED_PASSWORD with your desired passwords when changing or using the authentication credentials.