# Nodemcu cannot connect to mqtt

**URL:** <https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384>\
**Category:** General\
**Created:** [2 January 2021 08:43 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384 "2021-01-02T08:43:31Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [5 January 2021 06:18 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/24 "2021-01-05T06:18:49Z")

</div>

can you suggest me the way to solve this problem.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 January 2021 12:00 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/25 "2021-01-05T12:00:45Z")

</div>

> [@sam\_r](#):
>
> In firewall I already allow inbound rules and outbound rules but no success

are they set for 192.168.43.160?

What MQTT broker are you running?

---

<div class="post-metadata">

**Author:** ![Joaovitor](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joaovitor](https://discourse.nodered.org/u/Joaovitor)\
**Post date:** [5 January 2021 13:35 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/26 "2021-01-05T13:35:43Z")

</div>

Hello Friend.

Are you sure the messages have not been exchanged?

Remember that to view the debug node data you need to open the debug node menu.

It is the beetle on the upper right side.

Try this ...

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 03:00 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/27 "2021-01-06T03:00:11Z")

</div>

Any IP , port set 1883 , mosquitto 2.0.4 for windows 64

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 03:14 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/28 "2021-01-06T03:14:50Z")

</div>

I changed the mqtt server from my ip to localhost and done the test and its successful

 ![IMG_20210106_100610](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/670d80a2f351f5c2502b4786997e94c9fa508ea4.jpeg)

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 03:15 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/29 "2021-01-06T03:15:57Z")

</div>

Thanks Friend .. I was wrong and not checked the debug node menu

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 03:17 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/30 "2021-01-06T03:17:15Z")

</div>

Looks Mqtt is perfectely working but why my nodemcu is unable to connect to mqtt..  
What could be the reason ..

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 04:44 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/31 "2021-01-06T04:44:56Z")

</div>

If I use the ip address 192.168.43.160 as server then mqtt not connect , but if i use server as localhost the mqtt connected and the test is successful .. How can solve the issue, looks like the something is wrong with ip address , but I checking my ip by cmd ipconfig .. and in firewall also allowed .. what else do i need to check i am not getting .

My ip configuration is set to auto , not manual , if that could be the reason ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 January 2021 09:08 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/32 "2021-01-06T09:08:06Z")

</div>

> [@sam\_r](#):
>
> My ip configuration is set to auto , not manual , if that could be the reason ?

Yes, if the IP of the Broker changed then it wouldn't connect and if the IP of the Broker changed and the NodeMCU points to the old IP, then the Nodemcu would not be able to connect.

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 09:23 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/33 "2021-01-06T09:23:57Z")

</div>

But with the current ip also not connect .. if i modify the ip everywhere (arduino program, node flows) and put the present ip , still can't connect

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 January 2021 09:24 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/34 "2021-01-06T09:24:48Z")

</div>

is the broker configured to only listen to local connections ?

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 09:31 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/35 "2021-01-06T09:31:24Z")

</div>

how to check that ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 January 2021 09:34 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/36 "2021-01-06T09:34:52Z")

</div>

you need to look at the documentation of mosquitto 2.0.4 for windows 64

I think it may be the `listener port` option:

> `listener` _`port`_ _`[bind address/host/unix socket path]`_
> 
> Listen for incoming network connection on the specified port. A second optional argument allows the listener to be bound to a specific ip address/hostname. If this variable is used and neither the global `bind_address` nor `port` options are used then the default listener will not be started.
> 
> The `bind address/host` option allows this listener to be bound to a specific IP address by passing an IP address or hostname. For websockets listeners, it is only possible to pass an IP address here.
> 
> On systems that support Unix Domain Sockets, this option can also be used to create a Unix socket rather than opening a TCP socket. In this case, the port must be set to 0, and the unix socket path must be given.
> 
> This option may be specified multiple times. See also the `mount_point` option.
> 
> Not reloaded on reload signal.

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 09:47 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/37 "2021-01-06T09:47:16Z")

</div>

```auto
# listener port-number [ip address/host name/unix socket path]
#listener

# By default, a listener will attempt to listen on all supported IP protocol
# versions. If you do not have an IPv4 or IPv6 interface you may wish to
# disable support for either of those protocol versions. In particular, note
# that due to the limitations of the websockets library, it will only ever
# attempt to open IPv6 sockets if IPv6 support is compiled in, and so will fail
# if IPv6 is not available.
#
# Set to `ipv4` to force the listener to only use IPv4, or set to `ipv6` to
# force the listener to only use IPv6. If you want support for both IPv4 and
# IPv6, then do not use the socket_domain option.

```

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 09:47 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/38 "2021-01-06T09:47:50Z")

</div>

It saying it is open to all ip's

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 09:48 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/39 "2021-01-06T09:48:25Z")

</div>

it is saying it is listening to all ip's

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 January 2021 10:09 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/40 "2021-01-06T10:09:23Z")

</div>

have you reveriied that that is still the IP of the windows machine?

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 13:02 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/41 "2021-01-06T13:02:41Z")

</div>

The Ip changed but I have changed the ip in flow and arduino program also .. i am always using the latest ip in the program to test it ..

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 January 2021 14:32 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/42 "2021-01-06T14:32:52Z")

</div>

So with the new ip set in the MQTT nodes does the test flow work?

---

<div class="post-metadata">

**Author:** ![sam\_r](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sam\_r](https://discourse.nodered.org/u/sam_r)\
**Post date:** [6 January 2021 14:59 UTC](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384/43 "2021-01-06T14:59:30Z")

</div>

Test flow only works when i set server as "localhost" .. if i set server "192.168 .xx.xx " (my system ip address ) then mqtt only shows connecting and test flow does not work

[Previous page](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384.md?page=1)

[Next page](https://discourse.nodered.org/t/nodemcu-cannot-connect-to-mqtt/38384.md?page=3)
