It consists of a docker-compose file that launches an mqtt broker with restricting access: only clients that manage the same access credentials ( username and password ) at the connection time are served.
docker-compose
launches the broker mqtt. It listens onlocalhost:1883
. Themainloop.py
is used to interact with the broker, passing the authentication parameters. There is aconfig.json
file to set endpoint and credentials in order to interact with the broker. Changing username or password, the communication fails.
- It uses the
eclipse-mosquitto
image. There are two volumes to mount,mosquitto.conf
anddat.txt
. The first is a configuration file, the second contains username and encrypted password.
allow_anonymous false
password_file /mosquitto/data/dat.txt
- create a text file, like the figure below
-
install
mosquitto
-
now encrypt the password with the command
mosquitto_passwd -U <text_file>
. The result of the encryption is shown in the figure below
docker-compose up
python3 mainloop.py
If username and password used by the client are the same as those mounted on the broker, everything works. Vice versa the communication fails.