MQTT connection failed to broker, and ESP-01

I am having an issue with Node-red and the MQTT broker. I'll let you know, I am very new to Node-red, and my coding is amateur at best. I did not create the flow I am using, or the code. I do fine working with code, just not creating it.
Node-red works fine, except I get the repeating line "Connection failed to broker". I'm connecting my project through an ESP8266-01 to a wifi network, and to my Win 10 PC. I know I am probably missing something simple, but not sure where to look. Here is the NR log, and ESP code below. Let me know if you need any more info. Thanks!

3 Mar 10:02:22 - [info] Node-RED version: v2.0.5
3 Mar 10:02:22 - [info] Node.js version: v14.16.0
3 Mar 10:02:22 - [info] Windows_NT 10.0.19044 x64 LE
3 Mar 10:02:23 - [info] Loading palette nodes
3 Mar 10:02:24 - [info] Dashboard version 2.30.0 started at /ui
3 Mar 10:02:24 - [info] Settings file : C:\Users\mrdog.node-red\settings.js
3 Mar 10:02:24 - [info] Context store : 'default' [module=memory]
3 Mar 10:02:24 - [info] User directory : \Users\mrdog.node-red
3 Mar 10:02:24 - [warn] Projects disabled : editorTheme.projects.enabled=false
3 Mar 10:02:24 - [warn] Flows file name not set. Generating name using hostname.
3 Mar 10:02:24 - [info] Flows file : \Users\mrdog.node-red\flows_DRAGON2.json
3 Mar 10:02:24 - [info] Server now running at
3 Mar 10:02:24 - [warn]

Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.

3 Mar 10:02:24 - [info] Starting flows
3 Mar 10:02:24 - [info] Started flows
3 Mar 10:02:24 - [info] [mqtt-broker:288a79fc1071de7a] Connection failed to broker: mqtt://localhost :1883

And here is the code for the ESP in case it makes a difference. I only included the wifi and MQTT code for simplicity. I did set SSID and PW for my home network. The httpPort was just a test.

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "Arduino.h"

const char* ssid = "SSID";
const char* password = "Password";
const IPAddress mqttServerIP(192,168,254,14);
// const int httpPort = 1883;
const char* deviceID = "ESP8266";

WiFiClient wifiClient;
PubSubClient MQTTClient(wifiClient);
long lastMsgTime = 0;
char msg[64];
char topic[32];
int pulseCount = 0;

Have you installed an MQTT broker? If so then what broker have you installed, which computer have you installed it on, and which computer is node-red running on?

1 Like

Thanks for the quick response. No, I hadn't installed a broker, and feeling a bit ashamed I didn't realize it was an external thing from Node-red. So I installed Mosquitto and I'll work on figuring out how to set the configuration. All of this will be running on the same PC. Is there a simple tutorial for Mosquitto?

Quick edit, Node-red and Mosquitto are running, the broker connected, and I have a connection showing on my flow. OMG can't believe I missed that. Thank you!!!!!!

1 Like

It should just go if you accessing via localhost. You have to tweak it for access from a different machine, not at my pc so haven't got the details here. Has been addressed a few times here.

To learn all about MQTT then see this tutorial MQTT Essentials - All Core Concepts explained

1 Like

At my computer now. You have to add the mosquitto conf file

listener 1883
allow_anonymous true

That allows access to the broker without credentials from other machines on the network.

Where the conf file is depends on the OS and it looks as if you aren't using a Debian Linux so can't help there.

1 Like

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