Getting Mosquitto to work on a local domain (I use mqtt.local)

YunoHost 12.1.34 (stable)
mosquitto version 2.0.22

It took me some time to get this figured out so hopefully this may help others.

  1. Add a new domain

I used mqtt.local for this. I assume that one would need to adapt the default.conf file below for other domains / scenarios according to your requirements regarding websockets, TLS etc. but the comments in the original file are really helpful here (once you’ve found the file :blush:)

Install Mosquitto from the apps catalogue

When all’s up and running I ran these commands (as root or sudo su):

cp /etc/mosquito/conf.d default.conf /etc/mosquito/conf.d default.conf
(only for cowards like me who like to keep a copy of the original :blush:)

Edit the default.con file (I use nano here):

nano /etc/mosquito/conf.d/default.conf

My modified file looks then like this (btw.: I didn’t (yet) need to do the sudo yunohost firewall allow... command as port 1883 was already opened during installation):

log_timestamp_format %Y-%m-%dT%H:%M:%S

################### Direct IP

#To use mosquitto with direct IP call and no websocket protocol, uncomment those lines and comment

# those for websocket protocol

#You will need to open the firewall port with command "sudo yunohost firewall allow TCP 1883 --no-upnp"

listener 1883

###################SSL CONNECTION###########################################

#To use mosquitto with direct IP and SSL connection, uncomment those lines

#You will need to open the firewall port with command "sudo yunohost firewall allow TCP 8883 --no-upnp"

#listener 8883

#certfile /etc/yunohost/certs/mqtt.local/crt.pem

#cafile /etc/yunohost/certs/mqtt.local/crt.pem

#keyfile /etc/yunohost/certs/mqtt.local/key.pem

##############################################################################

#############################WEBSOCKET AND URL################################

#To use mosquitto with websocket protocol and a direct URL call, uncomment those lines and comment

#those for direct IP

#listener 1883 127.0.0.1

#listener 1883 ::1

#listener 8884

#protocol websockets

#certfile /etc/yunohost/certs/mqtt.local/crt.pem

#cafile /etc/yunohost/certs/mqtt.local/crt.pem

#keyfile /etc/yunohost/certs/mqtt.local/key.pem

#############################################################################

allow_anonymous false

password_file /etc/mosquitto/passwd

If you want to allow anonymous calls then modify the ”allow_anonymous false”

Line accordingly but I wouldn’t recommend this.

I was then finally able to go online:

Hope that this helps save other users’ time.

Fil

2 Likes

Nice !
@ericg could that be an option directly in the package in order to avoid manually editing a conf file ?

I have the same trouble.

Updating i run into the same problem than in The operation 'Upgrade the 'mosquitto' app' could not be completed

So i deinstall and install it fresh.

I have to manually change the /etc/mosquitto/conf.d/default.conf and comment all listener except listener 1883.

Think the package setup can enhance this by ask the user on install and allow changing this options.

Option in the package is on going : see Add & manage option to plain MQTT by ewilly · Pull Request #28 · YunoHost-Apps/mosquitto_ynh · GitHub