# Cannot connect to MQTT broker on local network

**URL:** <https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743>\
**Category:** General\
**Created:** [19 December 2020 04:20 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743 "2020-12-19T04:20:28Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![crustaceanhate](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crustaceanhate/32/33961_2.png) [@crustaceanhate](https://discourse.nodered.org/u/crustaceanhate)\
**Post date:** [19 December 2020 04:20 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/1 "2020-12-19T04:20:28Z")

</div>

Hey everybody,

I currently have node-red running on a Raspberry Pi Zero and so far it's been great, but I've been running into some issues connecting to an MQTT broker on my lan. I have Mosquitto v1.6.7 running on a Freebsd jail (hostname: mosquitto) on a server in my home network. A sensor (BME280 on a NodeMCU) is publishing data to this MQTT broker, and I can see the data being published successfully using MQTT Explorer running on a separate PC. For whatever reason, I cannot get the `mqtt in` node to connect to this broker. It just hangs with a yellow icon and `connecting`. Here are my settings:

![Screenshot from 2020-12-19 14-29-12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e15a265b8bc53477db3589cd1780949956c6c7ec.png)

I can ping `mosquitto.lan` from the RPi running node-red. I can also `ssh` into the RPi and subscribe to the messages from the command line i.e. `mosquitto_sub -h mosquitto.lan -t esp/bme280/temperature` and it connects successfully and displays the published temperature values. Also, if I run Mosquitto on the RPi, publish sensor data to that instead, and point the `mqtt in` node at it, everything seems to work. I can also connect to the [test.mosquitto.org](http://test.mosquitto.org) test broker from node-red. There is no security on the broker and it is set up to accept anonymous connections.

Does anybody have any suggestions?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 December 2020 07:05 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/2 "2020-12-19T07:05:25Z")

</div>

May I suggest you enter the IP number rather than the name.

Probably not important, but for the sake of eliminating this as a possible cause.

---

<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:** [19 December 2020 07:17 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/3 "2020-12-19T07:17:24Z")

</div>

How did you install node red? Are you using Docker?  
Stop node red and then start it in a terminal and see what it shows in the log. Paste the log here from the start. When pasting use the `</>` button at the top of the forum entry window.  
Also look at the mosquito log on the server and see what it shows when the pi tries to connect.

---

<div class="post-metadata">

**Author:** ![crustaceanhate](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crustaceanhate/32/33961_2.png) [@crustaceanhate](https://discourse.nodered.org/u/crustaceanhate)\
**Post date:** [19 December 2020 07:17 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/4 "2020-12-19T07:17:25Z")

</div>

A good suggestion, but I've tried that as well.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 December 2020 07:22 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/5 "2020-12-19T07:22:59Z")

</div>

If you are using other devices (eg: you mentioned esp/bme280) I am not sure how they are going to resolve the name.

I would again suggest you use the IP number on all devices.

What is the command you use from a terminal to send the messages? You have only shown how you are subscribing, but not publishing.

Could you copy/paste the terminal stuff you are doing?  
Or screen show with the two terminals open: one publish one subscribed.

---

<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:** [19 December 2020 07:41 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/6 "2020-12-19T07:41:42Z")

</div>

> [@Trying\_to\_learn](#):
>
> You have only shown how you are subscribing, but not publishing

The issue is that it won't connect, so whether it can publish is not relevant.

---

<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:** [19 December 2020 07:43 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/7 "2020-12-19T07:43:37Z")

</div>

Also try with the legacy support checkbox selected.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 December 2020 07:51 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/8 "2020-12-19T07:51:28Z")

</div>

Yes, ok. But I would like to see what is being sent as well and what is (not) being received.

So from a terminal seeing what is being sent would/may help.

But.... I'm not expert.

---

<div class="post-metadata">

**Author:** ![crustaceanhate](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crustaceanhate/32/33961_2.png) [@crustaceanhate](https://discourse.nodered.org/u/crustaceanhate)\
**Post date:** [19 December 2020 12:04 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/9 "2020-12-19T12:04:23Z")

</div>

Hey Colin, I installed it on a RPi running Raspbian GNU/Linux 10 using [this guide](https://nodered.org/docs/getting-started/raspberrypi), no Docker containers involved. Here's the log when starting it from a terminal using the `node-red-pi` command

```auto
Welcome to Node-RED
===================

19 Dec 11:18:59 - [info] Node-RED version: v1.2.3
19 Dec 11:18:59 - [info] Node.js version: v12.19.0
19 Dec 11:18:59 - [info] Linux 5.4.79+ arm LE
19 Dec 11:19:04 - [info] Loading palette nodes
19 Dec 11:19:18 - [info] Dashboard version 2.24.0 started at /ui
19 Dec 11:19:21 - [info] Settings file : /home/pi/.node-red/settings.js
19 Dec 11:19:21 - [info] Context store : 'default' [module=memory]
19 Dec 11:19:21 - [info] User directory : /home/pi/.node-red
19 Dec 11:19:21 - [warn] Projects disabled : editorTheme.projects.enabled=false
19 Dec 11:19:21 - [info] Flows file : /home/pi/.node-red/flows_raspberrypi.json
19 Dec 11:19:21 - [info] Server now running at http://127.0.0.1:1880/
19 Dec 11:19:21 - [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.
---------------------------------------------------------------------
19 Dec 11:19:22 - [info] Starting flows
19 Dec 11:19:26 - [info] Started flows
19 Dec 11:19:28 - [info] [mqtt-broker:237e7ff3.a6434] Connection failed to broker: mqtt://192.168.1.10:1883
19 Dec 11:19:44 - [info] [mqtt-broker:237e7ff3.a6434] Connection failed to broker: mqtt://192.168.1.10:1883
19 Dec 11:19:59 - [info] [mqtt-broker:237e7ff3.a6434] Connection failed to broker: mqtt://192.168.1.10:1883

```

The mosquitto log is showing the following error (192.168.1.8 is the ip address of the RPi)

```auto
1608379082: New connection from 192.168.1.8 on port 1883.
1608379082: Socket error on client <unknown>, disconnecting.

```

---

<div class="post-metadata">

**Author:** ![crustaceanhate](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crustaceanhate/32/33961_2.png) [@crustaceanhate](https://discourse.nodered.org/u/crustaceanhate)\
**Post date:** [19 December 2020 12:05 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/10 "2020-12-19T12:05:30Z")

</div>

I tried this. No dice.

---

<div class="post-metadata">

**Author:** ![crustaceanhate](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crustaceanhate/32/33961_2.png) [@crustaceanhate](https://discourse.nodered.org/u/crustaceanhate)\
**Post date:** [19 December 2020 12:10 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/11 "2020-12-19T12:10:39Z")

</div>

Hey @Trying_to_learn, I am publishing messages to the MQTT broker from an ESP8266, similar to what is described [here](https://randomnerdtutorials.com/esp8266-nodemcu-mqtt-publish-bme280-arduino/). I am using the IP address of the MQTT broker (192.168.1.10) on the ESP8266, rather than the hostname. Publishing seems to work fine, but I cannot subscribe to those messages from the node-red instance running on the RPi.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 December 2020 12:50 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/12 "2020-12-19T12:50:11Z")

</div>

> [@crustaceanhate](#):
>
> Freebsd jail

And how does the pub request arrive inside the jail? Do you need some kind of port forwarding?

---

<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:** [19 December 2020 13:43 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/13 "2020-12-19T13:43:41Z")

</div>

Run the install script again to upgrade node-red to the latest, there were some issues with 1.2.3, though I am not sure whether mqtt was involved. Always a good idea to do the easy things first though.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 December 2020 15:31 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/14 "2020-12-19T15:31:36Z")

</div>

If I remember right, 1.2.3 targets a version of MQTT that had issues. So updating to latest node-red should fix this.

---

<div class="post-metadata">

**Author:** ![crustaceanhate](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crustaceanhate/32/33961_2.png) [@crustaceanhate](https://discourse.nodered.org/u/crustaceanhate)\
**Post date:** [19 December 2020 22:15 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/15 "2020-12-19T22:15:33Z")

</div>

Upgraded to Node-RED v1.2.6 and everything's working now. Let that be a lesson to me to always upgrade to the latest version... or at least check the patch notes.

Thanks for your help everybody!

---

<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:** [2 January 2021 22:15 UTC](https://discourse.nodered.org/t/cannot-connect-to-mqtt-broker-on-local-network/37743/16 "2021-01-02T22:15:35Z")

</div>

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