I can't connect 2 IPs with mqtt in localhost

Hi, I'm Manu

I'm using an IOT from where I collect a digital signal coming from a photocell and transform it into a data insertion in a database, but I want to send it through mqtt from the IOT to a PC. It makes the connection ok but I'm not able to make the mqtt works. All this works in the same red.

Best regards

  1. What exactly is this IOT thing?
  2. What MQTT broker are you using
  3. Where is it installed?
  4. Does a simple flow like this work?

First of all, thank you for take your time with me.

  1. This IOT thing is a Siemens IOT 2040.
  2. Is necessary a mqtt broker in a local net? I want to send a message from an IP ( to I'm trying now mqtt explorer to see the messages.
  3. If i want to send the data from the IOT, i guess i need to install the mqtt broker in the IOT.
  4. Yes, i can do that in my IOT.

No, configure the MQTT node in the IOT to connect to the broker on the PC.

out of curiosity, when you say it makes the connection ok, between the devices, what are you using to determine that? what signal or message tells you the devices are connected?

You can use an mqtt broker in your local network or even on the internet.

On your local network is generally easiest.

The reason I asked what broker you have was to find out if you need any extra setup steps to make it accessible from all the devices on your network.
A commonly used broker is Mosquito. There is also Aedes broker which runs inside Node-red but is less powerful.

That's what i can't do, connect the devices. I can do a flow like this but only in one device. The thing is that i can't connect using mosquitto broker with 2 devices (the iot and the pc).

I know that i need to put the PC IP in the IOT to public the data and in the PC node i need to put the IOT IP to suscribe to the data. But i don't get it.

I'm using mosquitto broker yes. And i need to do the configuration in my local network.

Take a look at https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/.

Make sure that you have done all the necessary steps in the section " Enable Remote Access/ Authentication".
It is not specific to installing on a Pi, though I admit I have never installed on any other platform.

That doesnt sound right.

Whether you are publishing or subscribing, you need to put the IP address of the device where the broker is installed.

No, both the subscriber and publisher have to connect to the same broker, so both should use same IP. Except that on the pc you can use localhost instead, as that is effectively the same thing.

Maybe this will help you understand. With MQTT there are publishers, a broker and subscribers. These three parts could be on one or more devices. Let's say you setup a broker on a Pi Zero W and it has an IP address of


it's just sitting there waiting for a publisher or subscriber to connect to it.

Now you have this IOT device with an IP of The IOT device wants to publish data so it is a 'PUBLISHER'. It needs to send it's messages to a 'BROKER' using a 'topic' so it points at the existing BROKER at so now you have:


The IOT device doesn't care where the subscriber(s) are, that is the BROKERs worry, it just publishes data with a particular 'topic'

Now you have another device (your PC let's say it is IP running NR and it wants to receive the data from the IOT device. The MQTT-IN node needs to point at the BROKER and 'subscribe' to the TOPIC that the IOT device is using. So you have


Now when ever the Broker receives a msg, it looks at the topic and sends it to any device that has subscriber to that topic. Is =o if you have another device at, and it subscribed to the same topic, when ever the IOT published a msg, the broker would send that msg to the PC and the other device.

If you want to learn more about MQTT then see this tutorial MQTT Essentials - All Core Concepts explained

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