Mqtt connection ..failed

I want to try this basic ESP8266 MQTT example :

I want to publish a msg on Node-red

I started mosquitto .

But I'm getting this error ,:

Anyone have an idea where is the problem please?

not really node-red related - but you need to check the mosquitto logs on the box where you are running your mqtt broker for any entries

You might want to give a bit more detail as to your setup as well in terms of what is running Node-red mosquitto etc etc


I edited the post, I want to get the msg on node-red

OK so as i said

  1. What platform are you running on
  2. how did you get there ? i.e how was the install perforomed
  3. What is acting as your broker - presumably mosquitto - if so check the mosquitto log for reasons why your connection is being refused


  • I am on kali linux
  • install of what ??
  • How can I check the mosquitto log ?

For node-red to communicate it uses MQTT - you are trying to communicate from the ESP8266 to Node-red - the middle man is MQTT.

The MQTT software is setup to be a Broker.

Typically MQTT is provided on Linux by a program called Mosquitto (there are others) - i have no idea what kali linux provides - you do realise Kali is a security focused distribution for doing things like penetration testing and the like - it is not designed to be a daily drive (unless it has evolved way past what i saw last time i used it ?)

What box are you running Kali on and why are you running it rather than something mainstream ?


I am using mosquitto too in kali linux and it works good ,

I am running it just because I need to test some tools,
I use it as main OS,
What OS do you recommend me

Are you running this on a PC or a Raspberry PI ?

If a PC i prefer Centos but the majorirty of people use Ubuntu

You will need to find the Mosquitto log location on Kali - try /var/log/mosquitto as a good starting point.

Then you can tail the file and watch it to see if your ESP is talking to it correctly

Thank you I will try it,
But I didn't my ESP didn't connect to the mqtt server yet

Your code says your MQTT broker is at - that is the local loopback address of any device. This means the device thinks it is the MQTT broker.

You need to set that to the actual IP address of the machine that is the MQTT broker.

The one I got with the command : hostname -I ??

No, that just returns the local loop back address. try this
ifconfig wlan0
and you will get something like this:

pi@yellowpi:~ $ ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::4f3d:9a6e:9bd4:bbe8  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:40:54:1b  txqueuelen 1000  (Ethernet)
        RX packets 296708  bytes 76022934 (72.5 MiB)
        RX errors 0  dropped 408  overruns 0  frame 0
        TX packets 148026  bytes 35057664 (33.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

On the second lin see the inet? In my case my mqtt broker is running on so that is the adddress you need to enter in the code for the ESP8266
const char* mqtt_server = ""; but use your address not mine :joy:

I tried it and it works perfectly haha Thanks