Ich habe ein MQTT2_CLIENT Device definiert, dass die Verbindung zu einem Mosquitto-Server herstellt. Außerdem habe ich ein MQTT_GENERIC_BRIDGE Device eingerichtet. Jedes Mal, wenn ich etwas an der MGB ändere, oder MGB-relevante Dinge an einem anderen Device, kappt FHEM die Verbindung zum Mosquitto.
Mosquitto-Log
1769526503: Client FHEM closed its connection.
1769526503: New connection from 172.28.0.12:39504 on port 1883.
1769526503: New client connected from 172.28.0.12:39504 as FHEM (p1, c1, k30, u'username').
bzw. FHEM-Log
2026.01.27 16:04:12 1: mqtt.example.com:8883 disconnected, waiting to reappear (Mosquitto)
2026.01.27 16:04:13 1: mqtt.example.com:8883 reappeared (Mosquitto)
Warum ist das so?
MGB:
define mqttGenericBridge MQTT_GENERIC_BRIDGE mqtt hmThermostatWz_Climate
attr mqttGenericBridge IODev Mosquitto
attr mqttGenericBridge globalDefaults sub:base=fhem/set pub:base=fhem
attr mqttGenericBridge globalTypeExclude MQTT2_CLIENT MQTT_GENERIC_BRIDGE MQTT2_DEVICE
attr mqttGenericBridge room MQTT
attr mqttGenericBridge stateFormat dev: device-count in: incoming-count out: outgoing-count
# DEF mqtt hmThermostatWz_Climate
# FUUID 5c487d41-f33f-dc90-65d7-94f243d88ee56d2c
# FVERSION 10_MQTT_GENERIC_BRIDGE.pm:v1.4.4-s25117/2021-10-25
# IODev Mosquitto
# NAME mqttGenericBridge
# NR 129
# NTFY_ORDER 70-mqttGenericBridge
# STATE dev: 1 in: 15624 out: 31502
# TYPE MQTT_GENERIC_BRIDGE
# devspec hmThermostatWz_Climate
# eventCount 31580
# prefix mqtt
# READINGS:
# 2026-01-27 15:51:15 IODev Mosquitto
# 2026-01-27 15:44:45 attrTemplateVersion 20211208_MQTT
# 2026-01-27 16:08:23 device-count 1
# 2026-01-27 15:51:15 incoming-count 15624
# 2026-01-27 16:13:41 outgoing-count 31502
# 2026-01-27 16:13:41 transmission-state outgoing publish sent
# 2026-01-27 15:51:15 updated-reading-count 15616
# 2026-01-27 15:51:15 updated-set-count 4
# devices:
# :global:
# :alias:
# :defaults:
# pub:base fhem
# sub:base fhem/set
# hmThermostatWz_Climate:
# :alias:
# pub:measured-temp temperature
# sub:measured-temp temperature
# :publish:
# controlMode:
# last 1769526668.19316
# mode R
# topic {"$base/$device/$name"}
# desired-temp:
# last 1769526821.44074
# mode R
# topic {"$base/$device/$name"}
# humidity:
# last 1769526821.4419
# mode R
# topic {"$base/$device/$name"}
# measured-temp:
# last 1769526821.44308
# mode R
# topic {"$base/$device/$name"}
# :subscribe:
# globalDeviceExcludes:
# globalReadingExcludes:
# globalTypeExcludes:
# pub:
# FHEMWEB *
# Global *
# MQTT transmission-state
# MQTT2_CLIENT *
# MQTT2_DEVICE *
# MQTT_BRIDGE transmission-state
# MQTT_DEVICE transmission-state
# MQTT_GENERIC_BRIDGE *
# telnet *
# sub:
# FHEMWEB *
# Global *
# MQTT transmission-state
# MQTT2_CLIENT *
# MQTT2_DEVICE *
# MQTT_BRIDGE transmission-state
# MQTT_DEVICE transmission-state
# MQTT_GENERIC_BRIDGE *
# telnet *
# subscribe:
#
setstate mqttGenericBridge dev: 1 in: 15624 out: 31502
setstate mqttGenericBridge 2026-01-27 15:51:15 IODev Mosquitto
setstate mqttGenericBridge 2026-01-27 15:44:45 attrTemplateVersion 20211208_MQTT
setstate mqttGenericBridge 2026-01-27 16:08:23 device-count 1
setstate mqttGenericBridge 2026-01-27 15:51:15 incoming-count 15624
setstate mqttGenericBridge 2026-01-27 16:13:41 outgoing-count 31502
setstate mqttGenericBridge 2026-01-27 16:13:41 transmission-state outgoing publish sent
setstate mqttGenericBridge 2026-01-27 15:51:15 updated-reading-count 15616
setstate mqttGenericBridge 2026-01-27 15:51:15 updated-set-count 4
Danke!
Stefan
Ist am IO die subscriptions "durch das Programm" gesetzt?
Dann werden die vermutlich in dem Zusammenhang erneut.
Danke, war gesetzt. Aber das Entfernen leider nicht die Lösung. Verbindet sich immer noch bei jeder Änderung an einem Device neu.
Ein Verbose 5 des MQTT2_CLIENT bringt leider auch nichts brauchbares:
2026.01.28 10:26:39 5: Mosquitto: discarding DISCONNECT (224)(0)
2026.01.28 10:26:39 1: mqtt.example.com:8883 disconnected, waiting to reappear (Mosquitto)
2026.01.28 10:26:39 5: HttpUtils url=https://mqtt.example.com:8883/ NonBlocking via https
2026.01.28 10:26:39 4: IP: mqtt.example.com -> 192.168.2.16
2026.01.28 10:26:40 5: Mosquitto: sending CONNECT (16))(0)(6)MQIsdp(3)(194)(0)(30)(0)(4)FHEM(0)(9)user(0)(10)password
2026.01.28 10:26:40 5: DevIo_SimpleWrite Mosquitto: 102900064d514973647003c2001e00044648454d00096d6f7371756974746f000a4d307371756974746f21
2026.01.28 10:26:40 1: mqtt.example.com:8883 reappeared (Mosquitto)
Aber es ist leider gerade so viel Traffic am Mosquitto, dass keine vernünftige Recherche möglich ist. Ich hoffe, ich kann das später nachholen.
ZitatEin Verbose 5 des MQTT2_CLIENT bringt leider auch nichts brauchbares:
Kannst Du bitte in 00_MQTT_CLIENT.pm in der Funktion MQTT2_CLIENT_Disco vorne (z.Bsp. Zeile 282) eine Zeile mit
stacktrace();einfuegen?
Die zusaetzliche Ausgabe nach einem Restart sollte zu verkraften sein, da Disconnect nicht staendig passieren soll.
Mich würde ein list des MQTT2_CLIENT interessieren.
Zitat von: drhirn am 27 Januar 2026, 16:16:25Mosquitto-Log
1769526503: Client FHEM closed its connection.
1769526503: New connection from 172.28.0.12:39504 on port 1883.
1769526503: New client connected from 172.28.0.12:39504 as FHEM (p1, c1, k30, u'username').
bzw. FHEM-Log
2026.01.27 16:04:12 1: mqtt.intern.jft.at:8883 disconnected, waiting to reappear (Mosquitto)
2026.01.27 16:04:13 1: mqtt.intern.jft.at:8883 reappeared (Mosquitto)
Warum werden da Verbindungen auf unterschiedlichen ports (1883 & 8883) gelogged?
Stacktrace:
2026.01.28 16:39:02 1: stacktrace:
2026.01.28 16:39:02 1: main::MQTT2_CLIENT_Disco called by ./FHEM/00_MQTT2_CLIENT.pm (713)
2026.01.28 16:39:02 1: main::MQTT2_CLIENT_Write called by fhem.pl (1073)
2026.01.28 16:39:02 1: main::IOWrite called by ./FHEM/10_MQTT_GENERIC_BRIDGE.pm (1862)
2026.01.28 16:39:02 1: MQTT::GENERIC_BRIDGE::UpdateSubscriptions called by ./FHEM/10_MQTT_GENERIC_BRIDGE.pm (1799)
2026.01.28 16:39:02 1: MQTT::GENERIC_BRIDGE::UpdateSubscriptionsSingleDevice called by ./FHEM/10_MQTT_GENERIC_BRIDGE.pm (1706)
2026.01.28 16:39:02 1: MQTT::GENERIC_BRIDGE::_RefreshDeviceTable called by ./FHEM/10_MQTT_GENERIC_BRIDGE.pm (1735)
2026.01.28 16:39:02 1: MQTT::GENERIC_BRIDGE::RefreshGlobalTable called by ./FHEM/10_MQTT_GENERIC_BRIDGE.pm (2691)
2026.01.28 16:39:02 1: MQTT::GENERIC_BRIDGE::Attr called by fhem.pl (4007)
2026.01.28 16:39:02 1: main::CallFn called by fhem.pl (3224)
2026.01.28 16:39:02 1: main::CommandAttr called by fhem.pl (1285)
2026.01.28 16:39:02 1: main::AnalyzeCommand called by ./FHEM/01_FHEMWEB.pm (2860)
2026.01.28 16:39:02 1: main::FW_fC called by ./FHEM/01_FHEMWEB.pm (991)
2026.01.28 16:39:02 1: main::FW_answerCall called by ./FHEM/01_FHEMWEB.pm (614)
2026.01.28 16:39:02 1: main::FW_Read called by fhem.pl (4007)
2026.01.28 16:39:02 1: main::CallFn called by fhem.pl (789)
2026.01.28 16:39:02 5: Mosquitto: discarding DISCONNECT (224)(0)
2026.01.28 16:39:02 1: mqtt.example.com:8883 disconnected, waiting to reappear (Mosquitto)
2026.01.28 16:39:02 5: HttpUtils url=https://mqtt.example.com:8883/ NonBlocking via https
2026.01.28 16:39:02 4: IP: mqtt.example.com -> 192.168.2.16
2026.01.28 16:39:02 5: Mosquitto: sending CONNECT (16))(0)(6)MQIsdp(3)(194)(0)(30)(0)(4)FHEM(0)(9)username(0)(10)password
2026.01.28 16:39:02 5: DevIo_SimpleWrite Mosquitto: 102900064d514973647003c2001e00044648454d00096d6f7371756974746f000a4d307371756974746f21
2026.01.28 16:39:02 1: mqtt.example.com:8883 reappeared (Mosquitto)
2026.01.28 16:39:02 4: Mosquitto received CONNACK
2026.01.28 16:39:02 5: Mosquitto: received CONNACK (0)(0)
2026.01.28 16:39:02 5: Mosquitto: sending SUBSCRIBE (130)G(0)(25)(0)(30)fhem/set/Tedsen_SKX2xx_1F10110(0)(0)!fhem/set/hmThermostatWz_Climate/+(0)
2026.01.28 16:39:02 4: Mosquitto received SUBACK
2026.01.28 16:39:02 5: Mosquitto: received SUBACK (0)(25)(0)(0)
Mein Mosquitto läuft als Docker Container. Die Verbindung von FHEM zu Mosquitto läuft noch über einen Reverse Proxy. SSL (8883) zum Reverse Proxy, dann unverschlüsselt weiter (1883) zum Mosquitto Container. Mosquitto loggt also seine Container IP, FHEM aber die vom Reverse Proxy. Deswegen der Unterschied.
Da will GENERIC_BRIDGE Subscriptions per MQTT_CLIENT_WRITE setzen.
Ob man das wegoptimieren koennte, weiss ich nicht, die Funktion in MQTT2_CLIENT prueft nicht, ob dabei was Neues ist.
Finde ich irgendwie raus, was, wohin und warum da was schreiben will?
Jemand hat was getippt order geklickt auf der FHEMWEB Oberflaeche, um ein Attribut zu modifizieren, das hat GENERIG_BRIDGE abgefangen, und hat bei MQTT2_CLIENT eine Verbindung mit einer (neuen) subscription Liste bestellt.
Was bestellt wurde, kriegt man raus, indem man in MQTT2_CLIENT.pm, vor der Zeile 713 diese ausgibt mit z.Bsp.
Log 1, $topicMsg;Alternativ kann man auch verbose fuer die MQTT2_CLIENT Instanz(!) auf 5 setzen, und die Liste aus der Debug-Ausgabe, die SUBSCRIBE enthaelt, rausfischen.
Ah, verstehe. Ja, das war schon ich. Ich hab ein Attribut an einem Device geändert um den Reconnect zu provozieren.
Das heißt, das Kappen der Verbindung zum MQTT Broker ist Absicht?
Es ist ja im Prinzip keine große Tragödie. Ich hab nur eine Benachrichtigung eingerichtet, wenn die Verbindung zum Broker nicht da ist. Und die kommt so halt bei jeder Generic Bridge relevanten Änderung an einem Device. Sonst wär's mir eh nicht aufgefallen.