How to Set Up a Mosquitto MQTT Server

Mosquitto is a lightweight MQTT server that can run on the Raspberry Pi. Therefore, it is often my go-to MQTT server when I’m using Mycodo on a Raspberry Pi, since it an be easily installed on the same Pi that’s hosting Mycodo. The command to install mosquitto is:

sudo apt install mosquitto

Since version 2.0, mosquitto will allow local connections (i.e. from Mycodo installed on the same system), but not remote connections (a different device on the same network). If you want to use the mosquitto server with devices on your local network, you can edit /etc/mosquitto/mosquitto.conf and add the following two lines:

allow_anonymous true
listener 1883 0.0.0.0

Save, then restart mosquitto:

sudo service mosquitto restart

Note that this will allow anonymous access. If you would like to allow access outside your network, you should enable some form of authentication, either user/pass, SSH key, or something else. See Mosquitto Authentication Methods for more information about configuring authentication.

1 Like