mqtt broker

Einrichtung der openHAB Umgebung und allgemeine Konfigurationsthemen.

Moderatoren: seppy, udo1toni

Antworten
klaus1
Beiträge: 99
Registriert: 11. Jan 2022 13:48
Answers: 0

mqtt broker

Beitrag von klaus1 »

Hallo,

habe einen mqtt broker installiert, und bekomme immer:
COMMUNICATION_ERROR
io.netty.channel.AbstractChannel$AnnotatedConnectException: Verbindungsaufbau abgelehnt: /192.168.1.50:1883

im openhab.log:

Code: Alles auswählen

2023-05-26 08:40:38.219 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '192.168.1.50' with clientid 17bd8cee-e20f-420f-a906-ad4b6ecff73a
mosquitto ist installiert auf dem raspberrypi:

Code: Alles auswählen


root@raspberrypi:/var/log/openhab# sudo service mosquitto status
● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-05-26 08:37:27 CEST; 7min ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
    Process: 484 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 501 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUCCESS)
    Process: 509 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
    Process: 511 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
   Main PID: 513 (mosquitto)
      Tasks: 1 (limit: 1595)
        CPU: 343ms
     CGroup: /system.slice/mosquitto.service
             └─513 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Mai 26 08:37:27 raspberrypi systemd[1]: Starting Mosquitto MQTT Broker...
Mai 26 08:37:27 raspberrypi systemd[1]: Started Mosquitto MQTT Broker.

mosquitto log:

Code: Alles auswählen

1685083047: mosquitto version 2.0.11 starting
1685083047: Config loaded from /etc/mosquitto/mosquitto.conf.
1685083047: Starting in local only mode. Connections will only be possible from clients running on this machine.
1685083047: Create a configuration file which defines a listener to allow remote access.
1685083047: For more details see https://mosquitto.org/documentation/authentication-methods/
1685083047: Opening ipv4 listen socket on port 1883.
1685083047: Opening ipv6 listen socket on port 1883.
1685083047: Error: Cannot assign requested address
1685083047: mosquitto version 2.0.11 running
jemand eine idee? hab per backup openhab3 wieder installiert.

Benutzeravatar
udo1toni
Beiträge: 15247
Registriert: 11. Apr 2018 18:05
Answers: 242
Wohnort: Darmstadt

Re: mqtt broker

Beitrag von udo1toni »

Aber sicher :)
Es steht ja eigentlich alles da:
Config loaded from /etc/mosquitto/mosquitto.conf. Starting in local only mode. Connections will only be possible from clients running on this machine.
Der wichtigste Punkt dabei: Connections will only be possible from clients running on this machine.
Das heißt: der Broker ist nicht über die IP-Adresse 192.168.1.50 erreichbar (ich gehe mal davon aus, dass dies die IP-Adresse des Raspberry Pi ist), sondern ausschließlich über localhost (bzw. 127.0.0.1).

Das ist natürlich nicht Sinn eines Brokers, er soll aus dem gesamten LAN (oder zumindest einem Subnetz, falls man mehrere betreibt) erreichbar sein.
Öffne die angegebene Datei /etc/mosquitto/mosquitto.conf, aus der mosquitto seine Konfiguration bezieht:

Code: Alles auswählen

sudo nano /etc/mosquitto/mosquitto.conf
Vermutlich sieht die Datei so aus:

Code: Alles auswählen

# 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
Das Problem ist, der Listener Port muss zuerst definiert werden (und ebenso die Anweisung, Logins ohne User/Password zuzulassen). Ändere die Datei so ab:

Code: Alles auswählen

# 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

listener 1883
allow_anonymous true

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
und starte nach dem Speichern der Datei den Dienst neu:

Code: Alles auswählen

sudo systemctl restart mosquitto.service
Anschließend sollte mosquitto.log etwas in dieser Richtung enthalten:

Code: Alles auswählen

1685090611: mosquitto version 2.0.11 starting
1685090611: Config loaded from /etc/mosquitto/mosquitto.conf.
1685090611: Opening ipv4 listen socket on port 1883.
1685090611: Opening ipv6 listen socket on port 1883.
1685090611: mosquitto version 2.0.11 running
openHAB4.3.3 stable in einem Debian-Container (bookworm) (Proxmox 8.3.5, LXC), mit openHABian eingerichtet

klaus1
Beiträge: 99
Registriert: 11. Jan 2022 13:48
Answers: 0

Re: mqtt broker

Beitrag von klaus1 »

Herzliches Danke !!! TOP Antworten immer von dir!

Antworten