MQTT Installation
MQTT Installation
- Install
mosquittobroker andmosquitto-clientsclient packages.sudo apt -y update sudo apt -y install mosquitto sudo apt -y install mosquitto-clients
Configuration
- Configure the broker. The mosquitto broker’s configuration file is located at
/etc/mosquitto/mosquitto.conf. Open and edit this file. To configure MQTT broker to be authenticated.sudo vi /etc/mosquitto/mosquitto.conf - Delete this line.
include_dir /etc/mosquitto/conf.d - Add the following lines to the bottom of the file.
allow_anonymous false password_file /etc/mosquitto/pwfile listener 1883- anyone connecting to our broker need to provide username and password
- mosquitto to listen for messages on port number
1883 - If you don’t want the broker to require a username and password, don’t include the first two lines that we added.
- tell mosquitto what the username and password are. Replace
<username>with the username that you would like. Then enter the password you would like when prompted. When editing the configuration file, you specified a differentpassword_filepath, replace the path below with the one you usedsudo mosquitto_passwd -c /etc/mosquitto/pwfile <username> - Reboot RPi
sudo reboot - Start the broker
sudo service mosquitto start