-
Notifications
You must be signed in to change notification settings - Fork 42
Configuring Mosquitto MQTT server
MQTT is one of the most widely-used protocols for passing data from various hardware devices (e.g. Raspberry Pis, Arduinos, ESP32s) and the Node-REDscape control software. That requires an MQTT server to which all devices connect.
There are various nodes that provide MQTT servers from within Node-RED (e.g. the MOSCA/AEDES contrib nodes). However, while it is somewhat convenient to have the MQTT process start and stop from within your main Node-RED flow, it is also somewhat limiting. In general, I prefer to rely on Mosquitto (the, somewhat unofficial "standard" MQTT server), which has rock-solid reliability, great performance, and can run either on the same computer as the Node-RED instance, or on a seperate server if preferred.
I have a video introducing Mosquitto here: https://www.youtube.com/watch?v=VSwu-ZYiTxg
However, some details have changed since that video was made - most significantly is that from Version 2.x onwards, the default install no longer allows unauthorised or remote clients to connect. So, to use mosquitto with Node-RED:
- Download and install mosquitto from https://mosquitto.org/download/
- Create a passwords file containing credentials allowed to access the server. For a simple install, we can create the password file and add a single user to it using the following command:
mosquitto_passwd -c passwd.lst username
You will be prompted to enter the password for that user
Now, we need to make some changes to the mosquitto.conf file.
- Add a listener for incoming remote connections on port 1883:
listener 1883
- Specify that the server should check the credentials of any incoming connections against the password file we just created:
password_file passwd.lst
Now, we launch mosquitto (in verbose mode) using the modified config file, as follows:
mosquitto -v -c mosquitto.conf
Be sure that any client publishing or subscribing to the service supplies appropriate credentials as listed in the passwd.lst file, e.g.:
mosquitto_sub -u username -P password -h 192.168.1.52 -t #
mosquitto_pub -u username -P password -h 192.168.1.52 -m "Hi!" -t "FromDevice/2"
- Home
- Configuring Mosquitto MQTT Server
- Video Displays
- Sound and Lighting
- Events
- Functions
- Interfacing with External Devices