Mqtt client and mqtt broker connection

Case 1:
My mqtt Client (Arduino+ethernetshield) and broker (PC) are connected to same netwerk with my home router. mqtt attemps work fine.

Case 2:
In this case my mqtt Client and mqtt broker are connected to 2 different Networks. mqtt attemps not working.

Is it essential to connect mqtt Client and mqtt broker to a same Network???

Thank you.

When you say they are connected to 2 different networks what do you mean exactly?

If they are on completely different networks with no routing between them, then no, it isn't going to work.

Thank you @knolleary
I wanted to say that in Case 2, my mqtt Client is connected with one WiFi Network and my mqtt broker is connected to another WiFi Network.

Its not working.
I doubt , mqtt Client and mqtt broker should be connected to same Network.????

It depends what is between the two networks.

As the others have said. You need to understand a little about TCP/IP networking.

On a simple level, IP networks are split into segments (called "subnets") based on their addressing an a "mask".

A typical home network for example might have its router on as an internal address (not to be confused with the internet-facing external address which is different and assigned by your ISP). It will most likely have a mask (a "netmask") of You can see that information by opening a command prompt and (on Windows at least) running ipconfig -all.

That tells you that IP addresses between and can all be used by devices on that network. and are special addresses that we will ignore for now though they are actually on the same subnet.

The main purpose of your router is to route data between subnets. Usually it does nothing more than route between your internal and your external subnet. e.g from your local network to the Internet (strictly speaking to your ISP's network).

Now, when you talk about having two different WiFi networks, we cannot know whether those are both connected to the same home router or whether they are 20,000 miles apart on different sides of the world. So it is hard for us to give specific help.

All we can really say is that you need a router to get traffic from one network to another or you need to change the settings of your local network and the WiFi networks so that the two WiFi networks are reachable.

If you can give us more information about whether those WiFi networks are part of the same building or whether they are connected to the same router, we should be able to help further.

Thank you for your time. My one WiFi Network is 300 km away from the other WiFi Network.

OK, so now you hopefully understand that you need a mechanism to link between those 2 networks.

The most common approach for businesses is to have a site-to-site VPN (Virtual Private Network) create between the 2 networks. This effectively makes them a single network or at least an extended network. A VPN link is also encrypted on the wire to prevent eves-dropping or data alteration..

Otherwise, you have to make the broker available over the Internet. That, of course, brings its own complexities as you will still need to make firewall changes at the broker end and you will need to configure security and encryption of data in transit in the broker itself.

There are also quite a lot of other variations and technologies that could be used. It is really hard to give any ideas without needing to understand a lot more about your overall setup, who owns it, how it is configured, how much knowledge you have or have access to, etc.

Bottom line is that it isn't necessary to have the broker and client on the same network, but when they aren't, there are quite a lot of moving parts that need to be considered. It isn't all that hard as long as you have suitable access and some basic knowledge, but does require attention to detail if you want to avoid becoming another statistic.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.