# Node red fails to connect to mqtt broker

**URL:** https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111
**Category:** General
**Created:** [23 May 2021 13:13 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111 "2021-05-23T13:13:44Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ajocius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ajocius/32/19024_2.png) [@ajocius](https://discourse.nodered.org/u/ajocius)
#### Post date: [23 May 2021 13:13 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/1 "2021-05-23T13:13:44Z")

</div>

I have Mosquitto on RPI 3b that I used for couple of years now and did not do any changes in setting. RPI has restarted after power outage and gives me following error message when starting Node Red-

> 23 May 15:37:06 - [info] Starting flows  
> 23 May 15:37:07 - [info] Started flows  
> 23 May 15:37:07 - [info] [mqtt-broker:178b2db4.4b9292] Connection failed to broker: mqtt://192.169.1.29:1883  
> 23 May 15:37:07 - [info] [mqtt-broker:83ee96b6.cd6988] Connected to broker: mqtt://localhost:1883  
> 23 May 15:37:07 - [info] [mqtt-broker:378b7afe.ff3bc6] Connected to broker: mqtt://localhost:1883  
> 23 May 15:37:07 - [info] [mqtt-broker:b4426f3a.947b8] Connected to broker: mqtt://192.168.1.30:1883

Why does it fail and how can I fix it? Interesting that it connects to localhost, which is 192.168.1.29 in my case... but fails to connect directly to mqtt://192.169.1.29:1883

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 May 2021 13:42 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/2 "2021-05-23T13:42:48Z")

</div>

Have you got three separate mqtt broker nodes all pointing to the same broker? Two with localhost and one with the ip address? You should delete two of them and just use one.

What version of mosquitto are you using? V2.x requires access via ip address to be enabled in the config.  
`sudo apt policy mosquitto`

---

<div class="post-metadata">

### Author: ![ajocius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ajocius/32/19024_2.png) [@ajocius](https://discourse.nodered.org/u/ajocius)
#### Post date: [23 May 2021 13:44 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/3 "2021-05-23T13:44:48Z")

</div>

Not sure how can I delete nodes.

Here is output about mosquitto version:  
mosquitto:  
Installed: 1.4.10-3+deb9u4  
Candidate: 1.4.10-3+deb9u4  
Version table:  
\*\*\* 1.4.10-3+deb9u4 500  
500 [http://mirrordirector.raspbian.org/raspbian](http://mirrordirector.raspbian.org/raspbian) stretch/main armhf Packages  
100 /var/lib/dpkg/status

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 May 2021 13:50 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/4 "2021-05-23T13:50:42Z")

</div>

> [@ajocius](#):
>
> Not sure how can I delete nodes.

Go to the Menu dropdown \> Configuration Nodes from where you can click and hit delete key for two of them. When you deploy that the MQTT nodes using the deleted ones will show the red triangle and you can open them and select the remaining broker node.

You are using v1.4 so that doesn't explain the lack of connection. Are you certain the you have the right ip address? Check using  
`ip addr`

---

<div class="post-metadata">

### Author: ![ajocius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ajocius/32/19024_2.png) [@ajocius](https://discourse.nodered.org/u/ajocius)
#### Post date: [23 May 2021 13:54 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/5 "2021-05-23T13:54:06Z")

</div>

I do run Mosquitto on Raspberry Pi 3B, do not have Configuration Nodes on main RPI menu.  
I checked IP and it is correct:

> 3: wlan0: \<BROADCAST,MULTICAST,UP,LOWER\_UP\> mtu 1500 qdisc pfifo\_fast state UP group default qlen 1000  
> link/ether b8:27:eb:b5:74:b6 brd ff:ff:ff:ff:ff:ff  
> inet 192.168.1.29/24 brd 192.168.1.255 scope global wlan0  
> valid\_lft forever preferred\_lft forever  
> inet6 fe80::547b:b5aa:d763:864/64 scope link  
> valid\_lft forever preferred\_lft forever

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 May 2021 14:11 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/6 "2021-05-23T14:11:15Z")

</div>

Please post the full node red startup log so we can see more about your environment.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 May 2021 14:14 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/7 "2021-05-23T14:14:11Z")

</div>

> [@ajocius](#):
>
> 23 May 15:37:07 - [info] [mqtt-broker:178b2db4.4b9292] Connection failed to broker: mqtt://192.169.1.29:1883

That should be 168!

---

<div class="post-metadata">

### Author: ![ajocius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ajocius/32/19024_2.png) [@ajocius](https://discourse.nodered.org/u/ajocius)
#### Post date: [23 May 2021 14:17 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/8 "2021-05-23T14:17:36Z")

</div>

> [@Colin](#):
>
> That should be 168!

Wow, I am blind apparently, you are absolutely right.

How do I delete unnecessary nodes. My Mosquitto is running on Raspberry Pi 3B and I thought I have only command line option to adjust something on Mosquitto, do not have any front end application.

Here is complete startup log:

> Start Node-RED
> 
> Once Node-RED has started, point a browser at [http://192.168.1.29:1880](http://192.168.1.29:1880)  
> On Pi Node-RED works better with the Firefox or Chrome browser
> 
> Use node-red-stop to stop Node-RED  
> Use node-red-start to start Node-RED again  
> Use node-red-log to view the recent log output  
> Use sudo systemctl enable nodered.service to autostart Node-RED at every boot  
> Use sudo systemctl disable nodered.service to disable autostart on boot
> 
> To find more nodes and example flows - go to [http://flows.nodered.org](http://flows.nodered.org)
> 
> # Starting as a systemd service. Started Node-RED graphical event wiring tool.. 23 May 15:36:56 - [info] Welcome to Node-RED
> 
> 23 May 15:36:56 - [info] Node-RED version: v0.17.4  
> 23 May 15:36:56 - [info] Node.js version: v4.8.2  
> 23 May 15:36:56 - [info] Linux 4.19.66-v7+ arm LE  
> 23 May 15:36:57 - [info] Loading palette nodes  
> 23 May 15:37:02 - [info] Dashboard version 2.7.0 started at /ui  
> 23 May 15:37:05 - [warn] ------------------------------------------------------  
> 23 May 15:37:05 - [warn] [moment] SyntaxError: Unexpected token = (line:23)  
> 23 May 15:37:05 - [warn] ------------------------------------------------------  
> 23 May 15:37:05 - [info] Settings file : /home/pi/.node-red/settings.js  
> 23 May 15:37:05 - [info] User directory : /home/pi/.node-red  
> 23 May 15:37:05 - [info] Flows file : /home/pi/.node-red/flows\_raspberrypi.json  
> 23 May 15:37:05 - [info] Server now running at [http://127.0.0.1:7360/](http://127.0.0.1:7360/)  
> 23 May 15:37:06 - [info] Starting flows  
> 23 May 15:37:07 - [info] Started flows  
> 23 May 15:37:07 - [info] [mqtt-broker:178b2db4.4b9292] Connection failed to broker: mqtt://192.169.1.29:1883  
> 23 May 15:37:07 - [info] [mqtt-broker:83ee96b6.cd6988] Connected to broker: mqtt://localhost:1883  
> 23 May 15:37:07 - [info] [mqtt-broker:378b7afe.ff3bc6] Connected to broker: mqtt://localhost:1883  
> 23 May 15:37:07 - [info] [mqtt-broker:b4426f3a.947b8] Connected to broker: mqtt://192.168.1.30:1883  
> 23 May 15:37:22 - [info] [mqtt-broker:178b2db4.4b9292] Connection failed to broker: mqtt://192.169.1.29:1883  
> 23 May 15:37:37 - [info] [mqtt-broker:178b2db4.4b9292] Connection failed to broker: mqtt://192.169.1.29:1883

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 May 2021 14:41 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/9 "2021-05-23T14:41:28Z")

</div>

> [@ajocius](#):
>
> How do I delete unnecessary nodes.

You are using an ancient version of node red (0.17.4, current version is 1.3.5), and a very old version of nodejs (4.8.2, the current node red requires at least 8.x, but the recommended version is 12 or 14). I don't know how to delete config nodes on that version.  
If this is a stable system and you are not planning any more development with it then you can stick with what you have, as it is working, but if you plan further development then I suggest upgrading everything using the [recommended upgrade script](https://nodered.org/docs/getting-started/raspberrypi). That will upgrade node-red and nodejs. Back up anything vital on the pi first. I presume you have already backed up the flows file (which is referenced in the log you posted). Back up everything in that folder except the node\_modules folder which is huge and can be rebuilt anyway. Or even better an image backup of the SD card of course.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [6 June 2021 14:41 UTC](https://discourse.nodered.org/t/node-red-fails-to-connect-to-mqtt-broker/46111/10 "2021-06-06T14:41:47Z")

</div>

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