Run the following commands to install install mosquitto:
sudo apt install -y mosquitto mosquitto-clients
Make sure mosquitto service is enabled:
sudo systemctl enable mosquitto.service
Check of mosquitto is running:
ps -ef | grep mosquitto
Run mosquitto as a daemon:
mosquitto -d
Install paho-mqtt:
sudo pip3 install paho-mqtt
Get 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 start
To see if it's running:
service mqtt_subscriber/status
nano password_file
Add your credentials:
username:password
Substitute username
for your username and password
for your password.
Encrypt the file:
sudo mosquitto_passwd -U password_file
Run command:
sudo mosquitto_passwd -c password_file username
Substitute username
for your username and password
for your password.
Move the newly created password_file
to its proper location:
sudo mv password_file /etc/mosquitto
Edit the configuration file:
cd /etc/mosquitto
sudo nano mosquitto.conf
Add 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