# Mqtt not connecting to broker ip

**URL:** <https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551>\
**Category:** General\
**Created:** [19 March 2024 07:03 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551 "2024-03-19T07:03:29Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 07:03 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/1 "2024-03-19T07:03:29Z")

</div>

Hello All, Actually I bought new R-Pi 4. There inside I installed mosquitto broker and nodered also. And mosquitto.conf file inside edit the things for listener port 1883 and Allow Anonymous true.  
But still in my nodered not connected to the own ip with 1883 port.  
Can anybody help me figure out the problem?

---

<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 March 2024 07:06 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/2 "2024-03-19T07:06:10Z")

</div>

> [@neyarprasanth1](#):
>
> But still in my nodered not connected to the own ip with 1883 port.

Does 127.0.0.1 connect?

Have you tried using a standalone client like MQTT explorer to verify connectivity?

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 07:13 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/3 "2024-03-19T07:13:54Z")

</div>

@Steve-Mcl Just now I tried with 127.0.0.1:1880 also not connected. But I don't know Why,it's happening. Becoz I correctly config the all things.

---

<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 March 2024 07:18 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/4 "2024-03-19T07:18:07Z")

</div>

Is it running? Check your process manager and system logs. If you make a mistake in the config file, it usually doesn't start up (but does make a log entry)

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 07:20 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/5 "2024-03-19T07:20:59Z")

</div>

How can I check those things, I am make mistake or not. Can you tell any reference?

---

<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 March 2024 07:43 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/6 "2024-03-19T07:43:42Z")

</div>

Run `top` to check running processes

For logs, that depends on your OS and how/where you installed mosquitto.

If you try simply starting it from the terminal what do you see?

```auto
mosquitto 

```

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 March 2024 07:43 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/7 "2024-03-19T07:43:50Z")

</div>

I have the line  
`socket_domain ipv4`  
in mine as well - I can't remember why but maybe it'll help you out

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 07:50 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/8 "2024-03-19T07:50:39Z")

</div>

@Steve-Mcl When I entered the mosquitto, that time shows things are attached here. Refer the screen shot. But now it working for 127.0.0.1:1883. but not run for own ip.

 ![WhatsApp Image 2024-03-19 at 1.41.44 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/98ae449005cc56aeb34e8187c9b306c48cdb59bb.jpeg)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 March 2024 08:25 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/9 "2024-03-19T08:25:28Z")

</div>

Can you check the spelling of this command in your Mosquitto 'conf' file.  
It should have an underscore like this...

allow\_anonymous true

You'll need to stop and start Mosquitto after making any changes.

sudo systemctl restart mosquitto

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 08:36 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/10 "2024-03-19T08:36:22Z")

</div>

I attached my mosquitto.conf file and now I am faced issue also with using cmd is sudo systemctl status mosquitto and sudo systemctl start mosquitto. please refer those screenshots.

 ![WhatsApp Image 2024-03-19 at 2.03.30 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47fedd7df76db5776dcda2d8b63a5fa38c334874.jpeg)  
 ![WhatsApp Image 2024-03-19 at 2.00.28 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/8765b1e51754687f5448aad9578f5c551d7da90d.jpeg)  
 ![WhatsApp Image 2024-03-19 at 1.59.24 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/5711ca625c8a08f72da0e906f2ae648d90f9aa18.jpeg)

---

<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:** [19 March 2024 08:41 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/11 "2024-03-19T08:41:35Z")

</div>

Note: It is always better to copy what is on your screen and pasting it to a reply. This avoids people having a hard time seeing what you post

1. what OS are you running on your pi-4?
2. what version of mosquito did you install?

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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 March 2024 08:54 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/12 "2024-03-19T08:54:27Z")

</div>

Show us what appears in the mosquitto log file when you restart mosquitto using the systemctl command.  
Copy/paste please, not screen shot.

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 09:33 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/13 "2024-03-19T09:33:55Z")

</div>

I am using OS is "Debian GNU/LINUX 12(bookworm)  
mosquitto version is 2.0.11.

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 09:51 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/14 "2024-03-19T09:51:13Z")

</div>

@colin After restarted mosquitto shows this one.

```auto
raspberrypi@raspberrypi:~ $ sudo systemctl status mosquitto
● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; preset: en>
     Active: active (running) since Tue 2024-03-19 15:05:24 IST; 15s ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
    Process: 2320 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=ex>
    Process: 2322 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=ex>
    Process: 2323 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited>
    Process: 2324 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited>
   Main PID: 2325 (mosquitto)
      Tasks: 1 (limit: 3909)
        CPU: 33ms
     CGroup: /system.slice/mosquitto.service
             └─2325 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Mar 19 15:05:24 raspberrypi systemd[1]: Starting mosquitto.service - Mosquitto >
Mar 19 15:05:24 raspberrypi systemd[1]: Started mosquitto.service - Mosquitto M>
lines 1-17/17 (END)

```

but when i try to run mosquitto cmd only, it shows

```auto
raspberry@raspberrypi:~ $ mosquitto
1710840964: mosquitto version 2.0.11 starting
1710840964: Using default config.
1710840964: Starting in local only mode. Connections will only be possible from clients running on this machine.
1710840964: Create a configuration file which defines a listener to allow remote access.
1710840964: For more details see https://mosquitto.org/documentation/authentication-methods/
1710840964: Opening ipv4 listen socket on port 1883.
1710840964: Error: Address already in use
1710840964: Opening ipv6 listen socket on port 1883.
1710840964: Error: Address already in use

```

---

<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:** [19 March 2024 10:25 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/15 "2024-03-19T10:25:26Z")

</div>

Note I edited your last post. When posting code use the back tick **`** not **'**

Please copy and paste your mosquito config: `/etc/mosquitto/mosquitto.conf`  
and run `ls /etc/mosquitto/conf.d` and show the results  
also run `ls /run` and show the results

I notice in your mosquito.conf file you have  
`pid_file /run/mosquitto/mosquitto.pid` I want to make sure the file is actually in the `/run` folder. In my case it is in `/var/run`

---

<div class="post-metadata">

**Author:** ![neyarprasanth1](https://avatars.discourse-cdn.com/v4/letter/n/df705f/32.png) [@neyarprasanth1](https://discourse.nodered.org/u/neyarprasanth1)\
**Post date:** [19 March 2024 11:00 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/16 "2024-03-19T11:00:59Z")

</div>

This my /etc/mosquitto/mosquitto.conf data

```auto
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d
listener 1883
allow_anonymous true

```

And /var/run/mosquitto returns the permission denied

---

<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 March 2024 11:30 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/17 "2024-03-19T11:30:23Z")

</div>

You still haven't shown us what is in the mosquito log file.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 March 2024 11:36 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/18 "2024-03-19T11:36:23Z")

</div>

As @Colin said - can we see your mosquitto log file. Try this command and show us the listing...

```auto
sudo tail -20 /var/log/mosquitto/mosquitto.log

```

---

<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:** [17 June 2024 11:37 UTC](https://discourse.nodered.org/t/mqtt-not-connecting-to-broker-ip/86551/19 "2024-06-17T11:37:04Z")

</div>

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