The Mosquiito broker (server) can be configured to work as an MQTT bridge.
A bridge lets you connect two MQTT brokers together.
They are generally used for sharing messages between systems.
A common usage is connect edge MQTT brokers to a central or remote MQTT network.
Generally the local edge bridge will only bridge a subset of the local MQTT traffic.
In addition you only need to configure 1 of the brokers to act as the bridge, the other will act as a normal broker.
How it Works
When you configure the mosquitto broker as a bridge it becomes an MQTT client and subscribes and publishes to topics on the other broker and itself depending on the entries in the mosquitto.conf file.
Configuring the Broker
You will need to configure
- The Address and port of the remote broker or brokers. – Address keyword
- A client name. – Connection keyword
- What topics the broker will publish, and which topics it will subscribe to. -topic keyword
- Remapping if needed.
Note: You can configure multiple remote broker addresses and the broker will switch to another broker if the current broker connection fails.
Topic Bridging
What topics are being bridged and if they are being remapped is controlled by the topic entry.
The general format is
topic topic pattern direction QOS local prefix/remote prefix.
Direction can be out,in or both.
e.g.
topic house/sensor1 both 0 “” “”
topic_name=house/sensor1
direction both (could also be in and out)
QOS=0
Local_prefix=none
remote_prefix=none
The entries:
topic house/sensor1 in 0 “” “”
topic house/sensor1 out 0 “” “”
Are equivalent to the single entry:
topic house/sensor1 both 0 “” “”
The screen shot below shows how to bridge all topics with no remapping.
With the above configuration then:
- When a Client connected to broker 1 publishes on any topic that message will be sent to broker 2 . Example incoming message on topic house/sensor1 are published to broker 2 on topic house/sensor1.
- When a client connected to broker 2 publishes a message then messages published on any topic are sent from broker2 to broker 1.
Note: The messages are sent from broker 2 to broker 1 because broker1 subscribed to that topic on broker 2
Topic remapping is accomplished using topic prefixes.
The topic prefixes follow the QOS entry.
The screen shot below shows a remapping configuration for broker 1:
With the above configuration then:
- When a Client publishes on any topic that message will be sent to broker 2 with the topic prefix b2/. Example incoming message on topic house/sensor1 is published to broker 2 on topic b2/house/sensor1.
- When a client publishes a message to broker2 then messages published on b2/# are sent from broker2 to broker 1 but without the b2/ prefix. A message published to broker 2 on house/sensor1 is not sent to broker 2
Broker 2 Configuration
Broker2 is functioning as a normal broker (not a bridge) and doesn’t normally need any extra configuration.
Topic Bridging and Remapping
This is accomplished using the local and remote prefixes.
When the bridge on broker1 subscribes to a topic on broker2 it uses the form
remote_prefix + topic name e.g. b2/house/sensor1
When the bridge on broker1 subscribes to a topic on broker1 it uses the form:
local_prefix + topic name e.g. b1/house/sensor1
The following diagram illustrates the general process.
Bridging and Topic Remapping Examples
The following examples refer to the schematic above with two brokers broker1 and broker2 . Broker1 is configured as the bridge.
Normal clients will also be connected to both brokers.
Entry:
topic house/sensor1 both 0 “” “” or
topic house/sensor1 both 0
Also Equivalent to
topic house/sensor1 out 0
topic house/sensor1 in 0
Effect:
Incoming messages from a client connected to broker1 to a topic house/sensor1 are being bridged and will be sent to broker2 on topic house/sensor1.
Incoming messages from a client connected to broker2 on the topic house/sensor1. will be sent to broker1 on topic house/sensor1.
Entry uses remote prefix:
topic house/sensor1 both 0 “” b2/
Equivalent to
topic house/sensor1 out 0
topic house/sensor1 in 0 “” b2/
Effect:
Incoming messages from a client connected to broker 1 on the topic house/sensor1 are being bridged and will be remapped and sent to broker2 on topic b2/house/sensor1.
Incoming messages from a client connected to broker2 on topic b2/house/sensor1. will be sent to broker1 on topic b2/house/sensor1..
Broker1 removes the b2 prefix and will send them to clients subscribed to house/sensor1 on broker 1.
Entry uses local and remote prefixes:
topic house/sensor1 both 0 b1/ b2/
this is the same as:
topic house/sensor1 out 0 b1/ “”
topic house/sensor1 in 0 “” b2/
Effect:
Incoming messages from a client connected to broker1 on topic b1/house/sensor1 are being bridged and will be remapped and sent to broker2 on the topic b2/house/sensor1.
Incoming messages from a client connected to broker2 on the topic b2/house/sensor1. will be sent to broker1 on topic b2/house/sensor1.
Broker 1 removes the remote prefix (b2/) and then adds the local prefix (b1/) and will send them to clients subscribed to b1/house/sensor1 on broker 1
Working Example
Using the configuration shown above on broker 1 I am going to publish a message to broker 1.
Broker 1 has the bridge configured to connect to broker2 (IP address 192.168.1.157).
The topic bridging entry is:
topic # both 0 “” b2/
Broker 1 accepts messages and publishes them to broker 2 with a prefix of b2/.
Broker 1 subscribes to messages from from broker 2 on topic b2/#
Using a simple python client we will :
- Publish a message to broker1 on topic house/sensor1. Using a client name of P1
- Subscribe to broker2 on topic b2/house/sensor1 -Using client name of P2
When you start the broker on broker 1.
- It connects to broker 2 and subscribes to the topics b2/#.
- Connects to itself and subscribes to topic #
This can be seen from the console log messages:
When I run the script this is what I see.
Broker 1 receives message on topic house/sensor1 and publishes them to broker2 on b2/house/sensor1.
Broker2 receives messages on b2/house/sensor1 from broker1.
Backwards Testing
I can also publish to broker 2 on topic b2/house/sensor1 and it should be sent to broker 1 and made available as house/sensor1.
So now I will alter my script to send to broker 2 on topic b2/house/sensor1 and subscribe to house/sensor1 on broker 1.
Here is a screen shot of the results.
Notice the message is received by the client subscribed to broker 1 n the topic house/sensor1
Topic Remapping and Topic Republishing
Topic remapping takes an incoming topic and renames it.
E.g A broker would receive messages to topic sensor1 and remap them to new_sensor1.
Currently this form of remapping is not available, but prefix remapping is as shown above.
Topic republishing is done using an MQTT client and not a broker.
It can be used for more sophisticated remapping schemes but generates more traffic. See this python code example.
Bridging to Multiple Brokers- Round Robin
It is possible to bridge to another broker in the event of a broker failure.
To do so you need to set multiple address:port entries in the address field i.e
address 192.168.1.168:1883, 192.168.1.185:1883
will use broker 192.168.1.185 if the connection to the first broker (192.168.1.168) fails.
The round robin setting controls what happens when the original connection is restored. Here is the description taken from the online manual:
Authentication and Encryption
If the remote broker requires a username and password then you need to enter this using the remote username and remote password options.
You can also encrypt the connection between the brokers. This is likely to be a common configuration and Is covered in more detail in the Configure Mosquitto Bridge With SSL Encryption- Examples tutorial.
Looping
Publishing and subscribing to the same topic on the broker could result in a loop.
However if you try this you find that a broker detects that another broker sent the message, and doesn’t send the message back to it even though the broker has subscribed to that topic.
This confused me at first as looking through the specs I couldn’t find any reference for broker detection.
I did find this comment from Roger Light on a forum that explains it.
This seems to be triggered by the try private statement in the configuration file. This is what the config file states:
# If try_private is set to true, the bridge will attempt to indicate to the # remote broker that it is a bridge not an ordinary client. If successful, this # means that loop detection will be more effective and that retained messages # will be propagated correctly. Not all brokers support this feature so it may # be necessary to set try_private to false if your bridge does not connect # properly. #try_private true
Bridging to Thingspeak Note
I had a request for help regarding bridge configuration on mosquitto when creating a bridge to thingspeak.
If you need to do this you need the following two entries:
notifications flase
cleansession true
See this forum comment
Problems Encountered
When configuring bridges you may encounter some issues. Here are some of the errors I’ve encountered.
Error message on broker –socket error on client <unknown>disconnecting
Cause – Configuration file error. In my case it was the PSK setting.
Problem – Remapping not working as it should.
Cause -I forgot the QOS entry
Video -How to configure a bridged connection on the mosquitto mqtt broker
Related Articles and Resources:
- Mosquitto.conf documentation
- Connecting the last 100 metres –
- Owntracks -bridging
- Implementing SSL on the mosquitto broker.
Mosquitto Configuration Tutorials
- Installing The Mosquitto broker on Windows and Linux
- Quick Guide to The Mosquitto.conf File With Examples
- MQTT TLS Security – Mosquitto Broker Configuration
- Configuring and Testing MQTT Topic Restrictions
- Mosquitto username and Password Authentication Configuration Guide
- Configuring Logging on Mosquitto
Hi Steve,
Just been using hours on finding any one whom had made a mosquitto bridge to ThingsBoard IOT service. Your guide is the closest I could find. Thank you for it.
Have you done this (bridge to ThingsBoard) successfully and what would the .conf file look like ?
Thanks in Advance, Sami
Hi
Not sure if you can as thingsboard doesn’t supply a broker. Why can’t you just use a client?
Rgds
Steve
Thanks Steve for quick reply. As relative new to MQTT and Mosquitto …. what do you refere as client?
Just back ground what i’m trying to achive. So I have several Nodemcu + DHT11/CO2 sensors around house and logging indoor /outdoor temps and humidity and CO2 levels in house. All connected via LUA scirpt directly to Thingsboard.com. Works perfectly. Then as started to look for the CO2 levels I started work on project that the CO2 levels would be going also to my HVAC unit (connetec to NodemCU and TRIAC unit) and hence the levels would actually control the unit also. Here I managed to create a system in LUA that it send data to both two broker Thingsboard and Mosquitto. I was just looking would it be easier just to send the data to mosquitto and the re-distribute it to Thingsboard and I would not need to send it into two destinations from the NodeMCU’s.
Thanks !
Are you currently using MQTT to send the data to thingsboard or MQTT?
Rgds
Steve
Is it possible to run both local broker and the bridge on the same server, or would I need some fancy manger like docker?
Hi
Yes you can they just need to use different ports. This may help
How to Run Multiple mosquitto brokers on the same machine
https://youtu.be/dHH1kSQLhsU
rgds
steve
Thanks Steve, It’s very informative article.
Hi, Steve, I’m beginner here. I try to make the bridge between my local broker and CloudMqtt. Without bridg’s section in mosquitto.conf it start ok:
sudo systemctl status mosquitto
● mosquitto.service – LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto)
Active: active (running) since Wed 2019-02-20 21:17:03 +05; 1 day 12h ago
Process: 511 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mosquitto.service
└─531 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Feb 20 21:17:03 rsb mosquitto[511]: Starting network daemon:: mosquitto.
Feb 20 21:17:03 rsb systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
Feb 20 21:17:03 rsb mosquitto[531]: mosquitto version 1.3.4 (build date 2018-09-28 22:21:32+0000) starting
Feb 20 21:17:03 rsb mosquitto[531]: Config loaded from /etc/mosquitto/mosquitto.conf.
Feb 20 21:17:03 rsb mosquitto[531]: Opening ipv4 listen socket on port 1883.
Feb 20 21:17:03 rsb mosquitto[531]: Opening ipv6 listen socket on port 1883.
Feb 22 08:04:29 rsb mosquitto[531]: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
And when I add next strinngs in mosquitto.conf:
connection cloudmqtt
# address m99.cloudmqtt.com:55555
# try_private false
# notifications false
# start_type automatic
# remote_username uuu
# remote_password ppp
# topic # both
then I get mosquitto stopping:
pi@rsb:~ $ sudo systemctl status mosquitto
● mosquitto.service – LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto)
Active: active (exited) since Fri 2019-02-22 09:31:32 +05; 6s ago
Process: 933 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS)
Process: 940 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
Feb 22 09:31:32 rsb mosquitto[940]: Starting network daemon:: mosquitto.
Feb 22 09:31:32 rsb systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
Uncommenting strings above gives same result.
Help me please. Thanks!
The ping to CloudMqll presents and First the mosquitto starts The contain
hi
you need to enable the topic and address lines
rgds
steve
Thanks for the answer.
Now my mosquitto.conf contains lines:
connection mybridge
address m99.cloudmqtt.com:55555
try_private false
notifications false
start_type automatic
allow_anonymous false
remote_username nazmosq
remote_password *************
topic # both 0 “” “”
and mosquitto stopped:
pi@rsb:~ $ sudo systemctl status mosquitto
● mosquitto.service – LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto)
Active: active (exited) since Thu 2019-02-28 23:29:02 +05; 4s ago
Process: 969 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS)
Process: 976 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
Feb 28 23:29:02 rsb mosquitto[976]: Starting network daemon:: mosquitto.
Feb 28 23:29:02 rsb systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
Using mqtt-spy for connection with cloud-mqtt with such remote user is ok
What I must do?
/var/log/mosquitto/mosquitto.log is empty
I spent so much time for bridge..:(
What version of mosquitto are you using and what OS
rgds
steve
Today I passed to remote broker iot.eclipse.org without authentification. Mosquitto.conf contains lines
connection mybridge
address iot.eclipse.org
notifications false
start_type automatic
topic test001/# both 0 “” “”
But messages from the remote broker are not filtered according to a topic test001:
1551551860: Bridge rsb.mybridge doing local SUBSCRIBE on topic “”test001/#
1551551860: Connecting bridge mybridge (iot.eclipse.org:1883)
1551551860: Bridge rsb.mybridge sending CONNECT
1551551862: Received CONNACK on connection rsb.mybridge.
1551551862: Bridge rsb.mybridge sending SUBSCRIBE (Mid: 39, Topic: “”test001/#, QoS: 0)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m69, ‘test001/hum’, … (4 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 69)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m70, ‘test001/heap’, … (5 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 70)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m71, ‘test001/tdht’, … (4 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 71)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m72, ‘test001/heap’, … (5 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 72)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m73, ‘test001/tdht’, … (4 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 73)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m74, ‘test001/hum’, … (4 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 74)
1551551863: Received PUBLISH from rsb.mybridge (d1, q1, r0, m75, ‘test001/heap’, … (5 bytes))
1551551863: Sending PUBACK to rsb.mybridge (Mid: 75)
1551551863: Received PUBLISH from rsb.mybridge (d0, q0, r1, m0, ‘/034L2Xe68z/000/time’, … (73 bytes))
1551551863: Received PUBLISH from rsb.mybridge (d0, q0, r0, m0, ‘GSM_FLOW’, … (73 bytes))
1551551863: Received PUBLISH from rsb.mybridge (d0, q0, r1, m0, ‘/30c216b0ed/0/motion/perc’, … (11 bytes))
1551551863: Received PUBLISH from rsb.mybridge (d0, q0, r0, m0, ‘fedor’, … (100 bytes))
So I get
Socket error on client rsb.mybridge, disconnecting.
Steve, what I must write in line “topic..” ? Thanks!
Hi
Can you just give me a brief overview of the bridge you are trying to create.Use the ask steve page and I can respond via email
rgds
steve
This my problem is solved. I confused subscribed messages and the messages which are written down in mosquitto.log. For some reason messages come to the mosquitto.log without filtration according to topic. Thanks for your attention!
Hello.
Great tutorial, very helpful.
I want to bridge all topics in to my bridge but only some out. Still then, I couldn’t find a way of using wildcards to avoid havin to specify every topic individually as out…
My config for in topics is (this works beautifully):
topic # in 0
My doubt is with the out topics, which I wanted to filter (for instance, all that contain word Sonoff or sonoff. Something like:
topic *onoff* out 0
or
topic #onoff# out 0
But it doesn’t seem to work properly.
Any ideas on if I can do what I want and what am i doing wrong?
Thanks in advance,
Nuno
hi
you cannot use wild card characters as part of a name e.g string
sonof# doesn’t work but
sonoff/#
should work
* is invalid
I tried to make a bridge with test.mosquitto.org with mosquitto version 1.4.14 on Windows and the results worked. but when I tried it with version 1.5.4 the result failed, the error statement was “unknown error”, this happened when the local broker tried to connect to the remote broker (test.mosquitto.org)
This works when I make a bridge with a remote broker on the same PC
Hi
I have had others complain of bridge problems with mosquitto 1.5.4. I haven’t had chance to test it but it is probably nothing you are doing wromg.
How to establish a TCP Bridge connection.
Trying to TCP Bridge Mosquitto with EMQ.
Included the bridge connection in my mosquitto.conf
connection emq
address 172.22.25.53:2883
topic AB/# both 2
The IP address mentioned above is an IP of a different system. And also setup the port at 2883.
But the very rarely does the connection happen. It fails 95% of the times.
Where am i making a mistake?
Difficult to say. The mosquitto conf file that you included looks ok but missing a line like
connection bridge-emq
If that doesn’t work make sure that you can connect to emq using a normal client as it might have other restriction e.g authentication configured.
Let me know how you get on.
rgds
steve
Hello This solution can use for enterprise ? Anyone use for enterprise ? George
This is a very good post on MQTT bridge. TYou have given tips Encryption which is very useful for the user. They are able to make a bridge to connect with each other.
Hi steve, can we increase client connection limit from default 1024 to 10,000 in mosquitto?
I don’t find a proper solution from internet…so, it would be great for me if you can help in this problem..
Thank you!
☺️
From what I understand you can use -1 and have unlimited connections but the docs say that you might hit problems when you go over 1024.
# The maximum number of client connections to allow. This is
# a per listener setting.
# Default is -1, which means unlimited connections.
# Note that other process limits mean that unlimited connections
# are not really possible. Typically the default maximum number of
# connections possible is around 1024.
#max_connections -1
I am using Mosquitto MQTT Bridge between local gateway & remote MQTT broker server. It is working fine but when internet connection down then all topic published locally will not publish to broker when reconnect to internet even though QOS level is set to 2 and clean session flag is false so how can I ensure high quality of level between local MQTT bridge & remote MQTT broker without making retain topics. Is there any configuration from which local MQTT bridge ensure all topic sends to remote MQTT broker as or when internet connection resume?
It is not just the QOS on the bridge. Yoy need to be publishing to the bridge with a qos of 1 or 2 and subscribing on the remote broker with a qos of 1 or 2 and it should work.
You should also note that mosquitto has a limit of 100 messages (default) setting that it will hold in a queue.
HI Steve
I added following entry in broker2 mosquitto.conf file
connection Bridge1
address 127.11.0.1:1883
topic # both 0 “” b0/
That’s broker-2 as bridge, Broker1 as normal broker
Started normal broker first(broker1) and then bridge broker (broker2) later.
Used mosquitto_pub and mosquitto_sub to verify.
Case 1: Publishing from Broker2
# broker2:~# mosquitto_pub -t chassis/PSU0 -m “PSU0 is ON”
# broker1:~# mosquitto_sub -t b0/chassis/PSU0
PSU0 is ON
Case 2: Publishing from Broker1
#broker1:~# mosquitto_pub -t chassis/PSU0 -m “PSU0 is ON”
#broker2:~# mosquitto_sub -t chassis/PSU0
PSU0 is ON
Broker2 publishes them to broker1 with a prefix of b0/
Broker2 subscribes to all messages from broker1 with no prefix, is that correct ? I thought there would be /b0 this case as well.
Please clarify
No broker2 should subscribe to broker 1 using the prefix.
When you publish a message to broker1 then any message not beginning with the prefix b0/ isn’t sent to broker2.
When you send a message to broker2 it should send it to broker1 with the prefix.
In this case the prefix is both ways in and out.
Hi
Thank you first
I have question about bridge
Assume my broker can accept 10k users
If i use bridge,my brokers can 20k users?
Regards
The bridge will connect the topics to the other broker and The other broker can accept 10k users
So i can increase connection to many users with bridge
Thanks
Yes but you need multiple brokers
Hi Steve,
Great article. Quick question. Is there a practical limit to the number of brokers that can be bridged? In my project, I will have 100s of remote mqtt brokers. I’d like to pass status information from the remote brokers to my main cloud broker. The above configurations work great, but I’m unsure if there is a limit to the number of bridge connections (assuming the could version has the power to handle all of the incoming messages) a single instance can support.
Thanks,
James
Shouln’t be a problem as the cloud broker sees client connections it is the edge broker that is configured to be a bridge. The edge broker only needs to support 1 bridge to the cloud broker or 2 if you want a standby cloud broker.
Does that make sense?
Hi Steve,
When I bridge two mosquitto brokers in same laptop, it works. But not able to bridge two brokers in same network but both are running in different laptops. What could be the issue? Below is my configuration,
connection bridge-01
address 172.16.1.46:1883
topic # out 0
topic # in 0
please suggest
Regards
Pradeep
It sounds like a networking problem. Can you ping it? Do you have a firewall between the machines?
Thanks Steve for prompt response.solved.
I am trying to setup mosquitto cluster. Is it possible to achieve High availability(HA) and Load balancing(LB)?
As per my understanding, If I want to have cluster setup at cloud for HA and LB where mqtt gateways can publish data. It is not possible with mosquitto to achieve . Better I should choose another mqtt broker which gives HA/LB support and suitable for cloud.
Is my understanding correct? please suggest
Regards,
Pradeep
I haven’t looked at clustering mosquitto but I’ve seen several comments around the web saying you can’t do it.
You might want to look at HiveMQ
rgds
steve
Hi Steve,
I have done mosquitto clustering , please find architecture link below,
https://mosquitto-clustered-architecture.blogspot.in/2018/05/mosquitto-clustered-architecture-for_16.html
Regards,
Pradeep
i was getting “socket error on client (client id), disconnecting”
could you please help me why this error occurred and how to resolve this
Where are you getting the error? Does it occur on the broker that the bridge is trying to connect to? Do you have any security configured on the broker?
rgds
steve
Is bridging suitable for HA architecture where I want to have say three brokers that all share clients’ data?My concern is that it seems that even with Round Robin there is only one bridge so if that bridge broker goes down then HA breaks – am I missing something?
Bill
HA?
You’re correct the bridge is the weak link. The only alternative is to get the clients to publish to two brokers but that isn’t really practical.
Bridging doesn’t give you any kind f resilience it is only meant to connect brokers together so that they can share topics.
I am currently running a mosquito broker. I need to bridge this with mqtt broker running on m11.cloudmqtt.com. So as per your idea I need to do configuration on my mosquito.config file.Is it wright. I need to pass all messages publish all topics to remote broker and vice versa. Please provide comment on this
Yes
Edit the config file and start by bridging all topics. Once it is working ok then you can change it to only bridge selected topics.
In the simple configuration you have
topic # out 0 “” b1/
topic # in 0 “” b1/
But later you say
When the bridge on broker b1 subscribes to a topic on b2 it uses the form
remote_prefix + topic name e.g. b2/house/sensor1
Where does the b2 come from? I see no mentioning of b2 in the simple config.
Do you mean
topic # in 0 “” b2/
b2 is the remote prefix.The prefix is only used if you want topic remapping.You can use any prefix you want b2 is just an example.
I’ll reread the tutorial over the next few days and check to make sure the examples are OK as I remember when I was doing it it got confusing.
Thank you so much.
Best regards,
Vince
Hi Steve,
I am newbie in MQTT. I am using a Mosquitto broker in my laptop for home automation applications. It has worked well for local network but not for remote one. Could you guide me to configure the Mosquitto broker in order to access from outside network?
Many thanks in advance.
Vince Tran
Vince
you need to setup port forwarding on your home router. See this article
http://www.steves-internet-guide.com/understanding-port-forwarding/.
Alternatively you could use one of the free online brokers.
Rgds
steve
Here’s a tutorial I wrote up to help setup Mosquitto as a bridge to CloudMQTT for home assistant:
https://geekvisit.com/home-assistant-mosquitto-mqtt-cloudmqtt-work-mqtt-bridge/
Hope it helps
Hello Steve,
Many thanks for the help and it works great.
Just wanted to let you know. Kind regards
Hello Steve,
Very nice explanation on how to get this done. Could you please explain how to do this if say broker 2 has a username and password set up or TLS? Is it possible to configure in Broker 1, which is being used as the bridge a user name and password so it can access broker 2’s topic and publish to it?
Thanks and expecting your reply soon.
Hi
This tutorial covers the TLS http://www.steves-internet-guide.com/mosquitto-bridge-encryption/
For username and password authentication the broker that is acting as the bridge needs to use the remote username and remotepassword options. I will be edit the tutorial to cover this shortly.
Hello Steve,
Thanks for the quick response. I will be checking for the update, as I am in the middle of trying to develop my system now.
Kind regards
Hello Steve,
I am just putting together this configuration, but I don’t seem to understand where this configuration is to be. Is it a different script, or this is to be inputted into the mosquitto.conf file found in /etc/mosquitto/.
Regards
When Linux start mosquitto it will use the mosquitto.conf file in the /etc/nosquitto folder. So if you want to start mosquitto automatically then you need to place your changes in the mosquitto.comf file. If you start mosquitto manually from the command prompt which is normal when testing the you can use any conf file as you tell mosquitto which file to use using the -c switch. I use a file called m1.conf as it is short and easy to type. So I start mosquitto
mosquitto -c m1.conf
Hello Steve,
Many thanks for your quick responses, as I am beginning to get a hang of it now. The “connection “, what name exactly am I supposed to use, as can I just give it any name of my choice? below is my config, but the bridge seems not to be able to do anything as its finding it difficult to connect to my other broker:
#connection bridge-01
connection bridge-01
address 192.168.0.30:1883
topic home/sensor both 0 “” “”
remote_username
remote_password
Please is there something I am missing?
Regards
Hello Steve,
Many thanks for your quick responses, as I am beginning to get a hang of it now. The “connection bridge-01 “, what name exactly am I supposed to use, as can I just give it any name of my choice? below is my config, but the bridge seems not to be able to do anything as its finding it difficult to connect to my other broker:
#connection bridge-01
connection bridge-01
address 192.168.0.30:1883
topic home/sensor both 0 “” “”
remote_username myusername
remote_password mypassword
Please is there something I am missing?
Sorry had to send it again, as some text went missing in the last one I sent, and seems I can’t edit.
Regards
It looks Ok. Give it a try
Hi,
can you help on below issue , as my another bridge server denied publishing the data.
Sending SUBACK to CHATSRV-BRIDGE-USER
1492491690: | — mosquitto_auth_acl_check(…, local.KIBANA-BRIDGE-USER, AnonymouS, smart/, MOSQ_ACL_WRITE)
1492491690: | — mysql: topic_matches(smart, smart) == 0
1492491690: | — aclcheck(AnonymouS, smart/, 2) AUTHORIZED=0 by (null)
1492491690: | — Cached [86CCE31BFEB0B45E07246624715795ACE9151C96] for (local.KIBANA-BRIDGE-USER,AnonymouS,2)
1492491690: Denied PUBLISH from local.KIBANA-BRIDGE-USER (d0, q0, r0, m0, ‘smart/’, … (17 bytes))
Hi
I would look at the topic name as I’m not sure about the comma. Then I would see i the bridge as an access control list configured as that is when I’ve seen the publish denied message.
What broker are you using for the bridge?