Steps for Basic configuration and Install MQTT.
Open port TCP:1883 on firewall
Step 1: Install Mosquitto BrokerOpen port TCP:1883 on firewall
sudo apt-get update
sudo apt-get install mosquittoStep 2: Install Mosqitto clients
sudo apt-get install mosquitto-clients
mosquitto_sub -t "test"
Step 3: Testmosquitto_pub -m "message from mosquitto_pub client" -t "test"
Step 4: Secure with a Passwordsudo mosquitto_passwd -c /etc/mosquitto/passwd
Password:
RetypePassword:
sudo nano /etc/mosquitto/conf.d/default.conf
Paste below lines
allow_anonymous false
password_file /etc/mosquitto/passwd
Step 5: Restart serversudo systemctl restart mosquitto
Step 6: Testmosquitto_sub -t "test" -u "testuser" -P "testpassword"
Error
mosquitto_pub -t "test" -m "message from mosquitto_pub client"
Success
mosquitto_pub -t "test" -m "message from mosquitto_pub client" -u "testuser" -P "testpassword"
Step 7 — Configuring Mosquitto Over Websockets (Optional)sudo nano /etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 9001
protocol websockets
listener 1883 <ip-address>
Step 8 - Allow port in firewallsudo ufw allow 8083
Comments
Post a Comment