MQTT node show disconnected status

I'm learning how to publish LM35 temperature readings via MQTT with the ESP8266 (NodeMCU) to any platform that supports MQTT or any other MQTT client. I’ll publish sensor readings to Node-RED Dashboard and the ESP8266 will be programmed using Arduino IDE. However, MQTT node show disconnected status. I don't know how to solve that problem. I hope everyone will help me. Thank you.

Do you have a broker installed somewhere on your network (RPi? PC? Docker?) or are you using an internet broker?

Explain where (on the network) the broker is installed and what you have entered in the MQTT config node (a screenshot of the MQTT config node will do)

I have a broker installed on RPi

Can't help if you don't provide info

That is of little use as we don't know where node-red is running, and you have not shown us the mqtt config, as requested.
Also tell us what broker you are using and whether you have checked that it is working using something like MQTT Explorer.

I've tested on terminal and received this result.

That tells us mqtt works however, you haven't explained where node-red is installed, you haven't showed the MQTT config node. It is impossible to tell what the issue is if you don't explain the architecture.

I install node-red not only raspbian but also window. I've tested both of them, but the result still show disconnected.

hi @boyvip_123 welcome!! could you show us your MQTT node configuration!
are you using the same direction/IP of BROKER for node MQTT? for example:

Server : 127.0.0.1 or localhost
Port: 1883

How many times do we have to ask you to show us how you have configured the MQTT node? Do you not understand what is meant by that?

You have Mosquitto installed, no authentication, on your Raspberry Pi
Your test message "hello" was published to topic dev/test.

Assuming that you are running Node-RED on the same Raspberry PI:
Double click on the mqtt in node so that this pops up:


Click on the pencil.

Give the node a name and put "localhost" as the server.
Click Add.
Put "dev/test" in the topic field.
Click Done.
Click Deploy.
Does the node status show "Connected"?

After I click deploy, MQTT node show disconnected. For 10 seconds later, MQTT node show connecting.

If you look at the screenshots that you posted it explicity says that Mosquitto will only accept local connections because you have not created a configuration file.

Suggest you do that as per the mosquitto doc and then restart Mosquitto

Craig

it looks good, are the BROKER MQTT and Node RED working at the same Device (RPi)?
if your answer is yes; you could try put in Server property -> "localhost".

Captura de pantalla 2021-07-19 a la(s) 9.03.35 p. m.

are the BROKER MQTT and NodeRED working at the same Network?

you could try install and test the MQTT connection with MQTT Explorer or MQTT.fx

Yes. The BROKER MQTT and Node RED are working at the same Device (RPi).

Please show me how to add configuration file.

google is your friend

Mosquitto v2 config file linux will get you there

In fact it isn't necessarily that obvious what is the best way to do this by searching for it, some of the links that show up give poor advice.

There are two ways of configuring mosquitto on Linux. One is to modify the supplied default config file (in a pi that will be /etc/mosquitto/mosquitto.conf). This is not the best way of doing it because if you update mosquitto that file will get overwritten. A better way is to add a config override file in the folder /etc/mosquitto/conf.d, which overrides and adds to settings in the default file. That file will not get overwritten on an upgrade. The file can be called anything.conf. So for example to solve this particular problem you could create a file /etc/mosquitto/conf.d/mossy.conf containing

# Since mosquitto 2.0 have to specify listener and allow anonymous
listener 1883
allow_anonymous true