Run the following commands to install install mosquitto:
sudo apt install -y mosquitto mosquitto-clientsMake sure mosquitto service is enabled:
sudo systemctl enable mosquitto.serviceCheck of mosquitto is running:
ps -ef | grep mosquittoRun mosquitto as a daemon:
mosquitto -dInstall paho-mqtt:
sudo pip3 install paho-mqttGet the mqtt_subscriber.py script from this repo and place it anywhere on your server.
Move the MQTT Subscriber service and run it:
sudo cp mqtt_subscriber.service /etc/systemd/system
Reload systemctl and turn it on:
sudo systemctl daemon-reload
sudo systemctl enable mqtt_subscriber.service
sudo service mqtt_subscriber startTo see if it's running:
service mqtt_subscriber/statusnano password_fileAdd your credentials:
username:passwordSubstitute username for your username and password for your password.
Encrypt the file:
sudo mosquitto_passwd -U password_fileRun command:
sudo mosquitto_passwd -c password_file usernameSubstitute username for your username and password for your password.
Move the newly created password_file to its proper location:
sudo mv password_file /etc/mosquittoEdit the configuration file:
cd /etc/mosquitto
sudo nano mosquitto.confAdd the two following lines at the end:
allow_anonymous false
password_file /etc/mosquitto/password_file
Also be sure to look at the mosquitto.conf file in this repo for a full example.
Restart mosquitto service:
sudo service mosquitto restart