Jungletronics
Published in

Jungletronics

Mosquitto Bridge

How To Bridge Two Mosquitto Brokers — MQTT — Episode # 06

Fig 1. Our bridge set up. The default mosquito.conf file will be our broker0 and a modified broker1 mosquitto_br.conf file will implement our br-me-to-broker0 (see that tunneling is extended on the right side) — by working like this we can have devices (0,1,2) spread around the world. A true international sensor network! Can you imagine how cool is it? Cool! Very nice! This is where the fun happens!
Line#Description
210 # Port to use for the default listener.
211 port 1883
...
310 tls_version tlsv1.2
...
373 # listener port-number [ip address/host name]
374 listener 8883
...
431 # Certificate based SSL/TLS support453 # Path to the PEM encoded server certificate.
...
450 cafile C:\Program Files\mosquitto\certs\ca.crt
...
454 certfile C:\Program Files\mosquitto\certs\server.crt
...
457 keyfile C:\Program Files\mosquitto\certs\server.key
...
651 allow_anonymous false
...
669 password_file C:\Program Files\mosquitto\passwordfile.pwd
...
728 acl_file C:\Program Files\mosquitto\acl.acl
Line#Description
210 # Port to use for the default listener.
211 port 1884
...
310 tls_version tlsv1.2
...
373 # listener port-number [ip address/host name]
374 #listener
...
431 # Certificate based SSL/TLS support453 # Path to the PEM encoded server certificate.
...
450 #cafile
...
454 #certfile
...
457 #keyfile
...
651 allow_anonymous false
...
669 password_file C:\Program Files\mosquitto\passwordfile.pwd
...
728 acl_file C:\Program Files\mosquitto\acl.acl
...
755# =========================================================
756 # Bridges
757# =========================================================
...
792 connection br-me-to-broker0
793 address LAPTOP-JAYTHREE:8883
794 topic # both 0
...
817 cleansession false
...
839 notifications false
...
851 remote_clientid broker0
...
857 remote_password 123
...
863 remote_username admin
...
909 start_type automatic
...
922 try_private true
...
936 bridge_cafile C:\Program Files\mosquitto\certs\ca.crt
...
952 bridge_insecure false
...
955 bridge_certfile :\Program Files\mosquitto\certs\server.crt
...
958 bridge_keyfile C:\Program Files\mosquitto\certs\server.key
mosquitto -c mosquitto.conf -v
mosquitto -c mosquitto_br.conf -v
Fig 2. Now the two brokers are connected \o/
mosquitto_sub -h localhost -p 1884 -u user1 -P 321 -t temperature
mosquitto_pub -h LAPTOP-JAYTHREE -p 8883 -u user1 -P 321 --cafile ca.crt -t temperature -m 47
mosquitto_sub -h LAPTOP-JAYTHREE -p 8883 -u user1 -P 321 --cafile ca.crt -t temperature
mosquitto_pub -h localhost -p 1884 -u user1 -P 321 -t temperature -m 48
Fig 3. Here is the final result. Huge success! (To access the certifications we need to be at \certs directory)
Table 1. Summary of the two config files for your convenience ;-)
mosquitto -c mosquitto.conf -vmosquitto -c mosquitto_bd.conf -vmosquitto_sub -h localhost -p 1884 -u user1 -P 321 -t temperaturemosquitto_pub -h LAPTOP-JAYTHREE -p 8883 -u user1 -P 321 --cafile ca.crt -t temperature -m 47mosquitto_sub -h LAPTOP-JAYTHREE -p 8883 -u user1 -P 321 --cafile ca.crt -t temperaturemosquitto_pub -h localhost -p 1884 -u user1 -P 321 -t temperature -m 48

Related Posts

01# Episode — Mosquitto Intro To MQTT — It is Suitable for the Internet of Things Applications — MQTT

Credits & References

Microgênios — Treinamento em Sistemas Embarcados — Microchip Regional Partner — Microchip Certified Brazilian Training Education Company & A Simplício-Owned-Awesome Enterprise o/

--

--

J of Jungle + 3 Plats Arduino/RPi/Pic = J3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
J3

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!