[SOLVED] Mosquitto Broker address

hi all,
i have a problem with the start of mosquitto…in the log file i have:

2018-11-25 18:59:04.427 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.

2018-11-25 18:59:04.433 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘broker’

2018-11-25 18:59:04.637 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection

org.eclipse.paho.client.mqttv3.MqttException: Unable to connect to server

at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79) [205:org.openhab.io.transport.mqtt:1.12.0]

at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [205:org.openhab.io.transport.mqtt:1.12.0]

at java.lang.Thread.run(Thread.java:748) [?:?]

Caused by: java.net.ConnectException: Connection refused (Connection refused)

at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:?]

at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:?]

at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:?]

at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:?]

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]

at java.net.Socket.connect(Socket.java:589) ~[?:?]

at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70) ~[?:?]

... 2 more

but i have:
[19:13:46] openhabian@casa:~$ mosquitto -v
1543169704: mosquitto version 1.4.10 (build date Wed, 17 Oct 2018 19:03:03 +0200) starting
1543169704: Using default config.
1543169704: Opening ipv4 listen socket on port 1883.
1543169704: Error: Address already in use

if i reboot the sysyem and do mosquitto -v the connection works for some seconds (with a nodemcu with espeasy log i can see the connection)
and after that i have the status of connection to exited:
[19:06:02] openhabian@casa:~$ systemctl status mosquitto
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
Active: active (exited) since Sun 2018-11-25 18:58:10 CET; 8min ago
Docs: man:systemd-sysv-generator(8)
Process: 336 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCC
CGroup: /system.slice/mosquitto.service

Nov 25 18:58:10 casa systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broke
Nov 25 18:58:10 casa mosquitto[336]: Starting network daemon:: mosquitto.
Nov 25 18:58:10 casa systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker
lines 1-10/10 (END)

[19:13:38] openhabian@casa:~$ netstat -a | grep 1883
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN
tcp 0 0 casa.station:1883 computer-5.station:6609 ESTABLISHED
tcp6 0 0 [::]:1883 [::]:* LISTEN

how can i do for fix this problem? thanks to all

Please post your mqtt.cfg file located in $OPENHAB_CONF/services
Thanks

wow you are very fast!

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
broker.url=tcp://miohostname:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.

thanks to you

Try changing:

broker.url=tcp://casa:1883

to

broker.url=tcp://localhost:1883

or

broker.url=tcp://127.0.0.1:1883

And add:

broker.clientId=openhab2

Also, do you have the MQTT action installed?

sorry i see just now the old post is incomplete: (here i have insert the your modification)

# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
broker.url=tcp://127.0.0.1:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
broker.user=openhabian

# Optional. Password to authenticate with the broker.
broker.pwd=pass

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>
  broker.clientId=openhab2

seems to have the same problem with the modified mqtt.cfg file

What is the config in the nodemcu?

no, i haven’t MQTT action installed

in node mcu i have:
Unit name: NodeMCU_Prova
unit number: 0

esp ip: 192.168.0.7
esp gw 192.168.0.1
esp subnet 255.255.255.0
esp dns 192.168.0.1

controllers:
use hostname: miohostname
port: 1883
controller user: openhabian
controller pass: pass

Ok add the following at the very TOP of the mqtt.cfg file

pid:org.openhab.mqtt

And then restart OH

hi vzorglub,
now i have
sudo nano $OPENHAB_CONF/services/mqtt.cfg

pid:org.openhab.mqtt
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
broker.url=tcp://127.0.0.1:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
broker.user=openhabian

# Optional. Password to authenticate with the broker.
broker.pwd=pass

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

broker.clientId=openhab2

but i have the same problem:
systemctl status mosquitto

● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
   Active: active (exited) since Tue 2018-11-27 22:32:10 CET; 14s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1928 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS)
  Process: 1980 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)

Nov 27 22:32:10 casa systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker...
Nov 27 22:32:10 casa mosquitto[1980]: Starting network daemon:: mosquitto.
Nov 27 22:32:10 casa systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.

i see only now with the command “mosquitto -v” system write only (without "Error: Address already in use):

1543354581: mosquitto version 1.4.10 (build date Wed, 17 Oct 2018 19:03:03 +0200) starting
1543354581: Using default config.
1543354581: Opening ipv4 listen socket on port 1883.
1543354581: Opening ipv6 listen socket on port 1883.

EDIT: *only for the first time, after “mosquitto -v” doesn’t write the address error, the other times i have it

how can i be the only one having this problem? it’s the really base installation, only openhabian and mosquitto installed on raspberry

at the following in your mosquitto.conf (post the file contents here also):

listener 1883 0.0.0.0

now is:

 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 /var/run/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 0.0.0.0

but i have the same result

this command will try to start a mosquitto broker process (it doesn’t simply show you the version). The first time you run it, it will occupy port 1883.
you shouldn’t use this, but you should use the service

what is the output of:

ps -efw |grep mosquitto
netstat -atn |grep 1883
systemctl status mosquitto

doesn’t mosquitto broker start automatically at raspberry’s start?

ps -efw |grep mosquitto

openhab+ 1738 1683 0 22:18 pts/0 00:00:00 grep --color=auto mosquitto

netstat -atn |grep 1883

doesn't write a response on putty

systemctl status mosquitto

● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
   Active: active (exited) since Wed 2018-11-28 22:12:25 CET; 7min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 313 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCC
   CGroup: /system.slice/mosquitto.service

Nov 28 22:12:25 casa systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broke
Nov 28 22:12:25 casa mosquitto[313]: Starting network daemon:: mosquitto.
Nov 28 22:12:25 casa systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker

it does if you enable it

systemctl daemon-reload
systemctl enable mosquitto

try to start it with

systemctl start mosquitto

ok, i tried with

systemctl start mosquitto

also with

service mosquitto stop

service mosquitto start

but nothing of new…again exited

remove everything from your mosquitto.conf, put only these 2 lines and try again to start it:

user mosquitto
port 1883

check permissions on required dirs:

ls -al /var/lib/mosquitto/ /etc/mosquitto/ /var/log/mosquitto/

ls -al /var/lib/mosquitto/ /etc/mosquitto/ /var/log/mosquitto/
/etc/mosquitto/

total 28
drwxr-xr-x  5 root root 4096 Nov 28 22:54 .
drwxr-xr-x 94 root root 4096 Nov 25 16:46 ..
drwxr-xr-x  2 root root 4096 Nov 25 16:46 ca_certificates
drwxr-xr-x  2 root root 4096 Nov 25 16:46 certs
drwxr-xr-x  2 root root 4096 Nov 28 21:42 conf.d
-rw-r--r--  1 root root   25 Nov 28 22:54 mosquitto.conf
-rw-r--r--  1 root root  571 Nov 25 17:17 mosquitto.conf.save

/var/lib/mosquitto/:
total 12
drwxr-xr-x  2 mosquitto root      4096 Nov 25 17:04 .
drwxr-xr-x 34 root      root      4096 Nov 25 16:45 ..
-rw-------  1 mosquitto mosquitto   39 Nov 25 17:04 mosquitto.db

/var/log/mosquitto/:
total 32
drwxr-xr-x 2 mosquitto root       4096 Nov 25 19:00 .
drwxr-xr-x 8 root      root       4096 Nov 28 22:12 ..
-rw-r--r-- 1 mosquitto mosquitto 12425 Nov 28 22:12 mosquitto.log
-rw-r--r-- 1 mosquitto mosquitto  6079 Nov 25 18:36 mosquitto.log.save

permissions are ok
any progress with the “cut-down” mosquitto.cfg?

systemctl status mosquitto

● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
   Active: active (running) since Wed 2018-11-28 23:10:24 CET; 2min 18s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 325 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCC
   CGroup: /system.slice/mosquitto.service
           └─400 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Nov 28 23:10:24 casa systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broke
Nov 28 23:10:24 casa mosquitto[325]: Starting network daemon:: mosquitto.
Nov 28 23:10:24 casa systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker
lines 1-11/11 (END)

it works!!! thanks a lot to all!
now i have only to connect the nodemcu

1 Like

bring back one by one the mosquitto conf parameters to see where it explodes… :slight_smile:

do you have any config files in /etc/mosquitto/conf.d/ ?