Mosquitto setup - ahpohl/smartmeter-gateway GitHub Wiki

Overview

I have chosen the Eclipse Mosquitto MQTT broker because of the good API documentation and its simplicity to use (C API). I suspect any other MQTT implementation, i.e. Eclipse PAHO, would work equally well although I haven't tried any other apart from Mosquitto.

Installation

Arch Linux package:

$ yaourt -S mosquitto

Configuration

The Mosquitto broker has many configuration options and optionally supports password authentication and TLS connection encryption security.

Password authentication

For Smartmeter without TLS security only a very basic set of options needs to be enabled.

$ nano /etc/mosquitto/mosquitto.conf

listener 1883
password_file /etc/mosquitto/pwfile

Create the password file with default username mqtt and password mqtt:

$ mosquitto_passwd -c -b pwfile mqtt mqtt

Optional TLS security

There are many tutorials on the internet about how to setup your own CA to create TLS certificates for secure connections. I personally use Let's Encrypt certificates for my site, but you can use any certificates you wish. To enable TLS encryption in Mosquitto, additionally to the options above the following keys need to be enabled:

listener 8883
certfile /etc/mosquitto/ssl/cert.pem
keyfile /etc/mosquitto/ssl/privkey.pem
dhparamfile /etc/mosquitto/ssl/dhparam.pem
cafile /etc/ssl/certs/ca-certificates.crt

Create the Diffie-Hellman (DH) key-exchange parameters:

$ openssl dhparam -out /etc/mosquitto/ssl/dhparam.pem 2048

Automated startup

Mosquitto provides a systemd unit file:

$ systemctl enable mosquitto
$ systemctl start mosquitto