Search This Blog

Sunday 14 March 2021

Mosquitto MQTT Bridge

A bridge allows 2 mosquitto mqtt brokers to connect to each other. Only one broker needs to be configured.


Add the following config to mosquitto.conf file:

# =================================================================
# Bridges
# =================================================================
connection homeassistant
address 1.1.1.1:1883
topic # both 0
cleansession false
notifications false
remote_clientid broker0
remote_password mypass
remote_username myuser
start_type automatic

# =================================================================
# Listeners
# =================================================================
listener 1883 0.0.0.0


The above config will start a Listener on port 1883 and will connect to another broker 1.1.1.1 also on port 1883. The ports can be different but for the purpose of this example the default was used.


Test (1.1.1.1 is the standalone broker and 2.2.2.2 is the bridge broker):

 # mosquitto_sub -h 1.1.1.1 -p 1883 -t '#' -u myuser -P mypass
0
1

/ # mosquitto_sub -h 2.2.2.2 -p 1883 -t '#' -u myuser -P mypass
0
1

The same messages are being received. 2.2.2.2 gets the messages from 1.1.1.1 because it acts as a bridge.

No comments:

Post a Comment

Nornir Compliance Check