-
Notifications
You must be signed in to change notification settings - Fork 1
Managing the MQTT to MongoDB passthrough servers
Author: Will Richards
To gain access to manage the pass through servers please talk to Chet Udell about getting an SSH user on the server. (FOR OPEnS Only)
On the server there are two main programs that we always want running to be able to service connections at any point. These two programs are Mosquittoand Node-RED. Mosquitto brokers the MQTT connections from the devices themselves while Node-RED handles the pass through from the MQTT broker to the MongoDB database for long-term storage.
As such both the Mosquitto broker and the Nod-RED instance must be running 24/7.
This config is more or less just standard configuration for an unsecured, authenticated MQTT broker.
# Configure remote listener on any network interface
listener 1883 0.0.0.0
# Disable anonymous login
allow_anonymous false
# Select a password file to retain the credentials
password_file /etc/mosquitto/passfile.txt
To generate a password file follow this tutorial
To configure node-red a configuration will need to be downloaded from here. Setup the connections for MQTT and MongoDB to route to your specific server
Node-RED runs persistently using pm2 while Mosquitto is installed as a systemd service to start the Mosquitto services run
sudo systemctl start mosquitto.service
pm2 start /usr/local/bin/node-red
After you have started node-red you want to run
pm2 save
Doing so allows you to generate the startup command we need
sudo systemctl enable mosquitto.service
pm2 startup
<RUN THE COMMAND IT GIVE YOU>
Next you need to edit the file /etc/systemd/system/pm2-username.service
4: After=network.target
->
4: After=network.target mosquitto.service