# Mqtt nodes not connecting

**URL:** <https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950>\
**Category:** General\
**Created:** [11 January 2021 12:58 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950 "2021-01-11T12:58:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 12:58 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/1 "2021-01-11T12:58:39Z")

</div>

I'm running node-red in a cloud server. All mqtt nodes show a yellow "connecting" label, but they never achieve the connection. How can I find the problem?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 January 2021 13:08 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/2 "2021-01-11T13:08:32Z")

</div>

Find where your mqqt broker is, then compare this with your NR config

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 13:22 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/3 "2021-01-11T13:22:56Z")

</div>

The mqtt broker is in the same cloud server  
Plus I get a message in the console, from node-red: [info] [mqtt-broker:5e25a454.56e434] Connection failed to broker: node-red@mqtt://localhost:1883  
Don't know what to compare

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 January 2021 13:27 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/4 "2021-01-11T13:27:20Z")

</div>

You've not really told us anything about the environment so we can't really help.

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 13:44 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/5 "2021-01-11T13:44:50Z")

</div>

Sorry, I'm trying to set up an iot platform, so I got a cloud server, using ubuntu 18.04 with apache server, a db, a mosquitto mqtt server and node-red. I built a node red flow with several input and output to mqtt, and it puts a tag every 15 seconds, that is when it gives the [info] message above.  
Node-red is v1.2.6, , node.js is v8.10.0  
The connection to the db seems fine, but with the mqtt broker doesn't  
Any other thing that can help?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 January 2021 14:10 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/6 "2021-01-11T14:10:12Z")

</div>

Verify connection to mqtt broker with some other tool/client

- are you sure mqtt broker is running and listening?
- port, ip, userid+pw, tls???
- show your flow/config of mqtt connection

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 16:10 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/7 "2021-01-11T16:10:54Z")

</div>

1610380939: Socket error on client , disconnecting.  
1610380954: New connection from 127.0.0.1 on port 1883.  
1610380954: Sending CONNACK to 127.0.0.1 (0, 5)  
This is mosquitto log  
And the flow:

 ![imagen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/dffa3a633bea70debf30fbf92f680cba83ac1eb8.png)

---

<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:** [11 January 2021 16:30 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/8 "2021-01-11T16:30:10Z")

</div>

Can you show a bit more of the log please.

---

<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:** [11 January 2021 16:32 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/9 "2021-01-11T16:32:27Z")

</div>

Also please export the three mqtt nodes and paste them here, using the `</>` button at the top of the forum entry window when pasting it in.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [11 January 2021 16:34 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/10 "2021-01-11T16:34:50Z")

</div>

What version of Mosquitto broker are you using ?

Are you using authorization as @krambriw asked ?

According to this post on [Github](https://github.com/eclipse/mosquitto/issues/1177#issuecomment-484145521) (0,5) is related to authorization.

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 17:29 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/11 "2021-01-11T17:29:16Z")

</div>

This is the full log, it keeps repeating every 15'

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 17:32 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/12 "2021-01-11T17:32:46Z")

</div>

mosquitto is v1.4.15

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [11 January 2021 17:37 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/13 "2021-01-11T17:37:21Z")

</div>

Im not an expert with MQTT but that version is since 2018 .. is it possible to update to a more recent version ? 😉

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 17:37 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/14 "2021-01-11T17:37:28Z")

</div>

![imagen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16764bfebd59f5491715250496dc4c1ec5d7e06c.png)

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 17:41 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/15 "2021-01-11T17:41:31Z")

</div>

This is one of the mqtt nodes

 ![imagen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01bdabb4a36987a17da59dfb2a7c9efb7afae773.png)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 January 2021 17:44 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/16 "2021-01-11T17:44:13Z")

</div>

So have you configured the mqtt broker correctly to accept the user login???

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 17:44 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/17 "2021-01-11T17:44:43Z")

</div>

And this is the full mosquitto answer:  
1610386283: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting  
1610386283: Using default config.  
1610386283: Opening ipv4 listen socket on port 1883.  
1610386283: Error: Address already in use

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 January 2021 17:45 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/18 "2021-01-11T17:45:53Z")

</div>

So you have already one instance of the broker running on port 1883. Put here a copy of what you get when you run the command ps aux

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [11 January 2021 17:47 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/19 "2021-01-11T17:47:40Z")

</div>

First step before even thinking of NR, have you tried to use the mosquitto client to publish and subscribe and see if that works?

> **[mosquitto\_pub man page](https://mosquitto.org/man/mosquitto_pub-1.html)**
>
> Name
> mosquitto\_pub — an MQTT version 5/3.1.1/3.1 client for publishing simple messages
> 
> 
> Synopsis
> mosquitto\_pub { 
> \[-h hostname\]
> \[--unix socket path\]
> \[-p port-number\]
> \[-u usern

> **[mosquitto\_sub man page](https://mosquitto.org/man/mosquitto_sub-1.html)**
>
> Name
> mosquitto\_sub — an MQTT version 5/3.1.1/3.1 client for subscribing to topics
> 
> 
> Synopsis
> mosquitto\_sub { 
> \[-h hostname\]
> \[--unix socket path\]
> \[-p port-number\]
> \[-u username\]

---

<div class="post-metadata">

**Author:** ![ega](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@ega](https://discourse.nodered.org/u/ega)\
**Post date:** [11 January 2021 18:03 UTC](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950/20 "2021-01-11T18:03:10Z")

</div>

root 20266 0.0 0.0 14864 1072 pts/1 S+ 18:00 0:00 grep --color=auto mosquitto  
mosquit+ 23892 0.0 0.2 48152 4104 ? S 2020 8:16 mosquitto -c /etc/mosquitto/conf.d/broker.conf -v

[Next page](https://discourse.nodered.org/t/mqtt-nodes-not-connecting/38950.md?page=2)
