MQTT Broker Setup on CMTK
2. Setup Internet Access
- Conect LAN2 Port on the CMTK to your router
- Go to the "Netwrok Settings tab and set the LAN2 port as a DHCP client and press save.
- If wired and configured properly, the IP address information should be poplulated.you should be able to use the Ping Server to successfully ping the balluff.com URL.
- You should be able to use the "Ping Server" function to successfully ping balluff.com
3. Open Portainer
- Go to the "Settings Tab" --> Docker --> Open Portainer
- Input your credentials and login. If this is the first time logging into portainer, it will prompt you to create a user name and password.
4. Create the MQTT Broker
- Once logged into Portainer, navigate to the "Stacks" tab.
- Create a Stack
- Give the stack a name. It must be lowercase characters. In this example, the name is "mqtt".
- Select "Web editor" as the build method
- Copy and paste the following into the web editor. You can change the port numbers if you would like to, in this example it is set to "50008:50008"
-
services:
mosquitto:
image: eclipse-mosquitto:latest
container_name: MQTT_Broker
ports:
- "50008:50008"
volumes:
- mosquitto_config:/mosquitto/config
- mosquitto_data:/mosquitto/data
- mosquitto_log:/mosquitto/log
restart: always
volumes:
mosquitto_config:
mosquitto_data:
mosquitto_log:
-
- Click "Deploy the Stack"
- Go to the "Volumes" tab and confirm the volumes were created. There should be a total of three (log, config, and data).
- Go to the "Containers" tab. There should be a newly created container running with the name "MQTT_Broker". Under the Quick Actions column, click on the "Exec Console" command.
- Select " /bin/sh" as the command and click "Connect"
- Input the following commands:

- Change Directory
- cd/mosquitto/config
- Allow listener on the port (50008 for this example)
- echo "listener 50008" > mosquitto.conf
- Do not allow anonymous connection
- echo "allow_anonymous false >> mosquitto.conf
- Create a password file
- echo "password_file /mosquitto/config/passwordfile" >> mosquitto.conf
- Set your username
- mosquitto_passwd -c passwordfile admin
- I am using admin as the username. If you would like to change the name, modify the end of the command by changing admin to your desired name.
- Once you hit enter, it will prompt you to enter a password and then prompt you to re-enter the password for confirmation. When entering the password, the characters will not display on the screen.
- Command to confirm config settings
- cat mosquitto.conf
- cat mosquitto.conf
- You can also set the allow anonymous to true instead of false, which will make it where a username and password does not need to be input to access the broker. If setting this to true, you do not need to run the "mosquitto_passwd -c passwordfile admin" command.
- echo "allow_anonymous true" >> mosquito.conf
-
- cd /mosquitto/config
- Go back to the "Containers" tab to stop the container and then start it again. This will allow for the configuration setting done in the previous step to take effect.
- Stop the container

- After stopping the container, start it back.

- You can now use the MQTT broker to store data from a MQTT device.











