Mqtt not connecting to broker ip

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?

Does connect?

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

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

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)

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

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?


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

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

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

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.

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 ```)

   code goes here 

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

See this post for more details - How to share code or flow json

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

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

@colin After restarted mosquitto shows this one.

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)
    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

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
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

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/ I want to make sure the file is actually in the /run folder. In my case it is in /var/run

1 Like

This my /etc/mosquitto/mosquitto.conf data

# 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/

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

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

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

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