iobroker-community-adapters / ioBroker.mqtt-client

Publish and subscribe ioBroker states to MQTT Brokers
MIT License
11 stars 10 forks source link

This adapter send no lastwill out #65

Closed ThomasLoeffel closed 2 years ago

ThomasLoeffel commented 3 years ago

Describe the bug
This Adapter in Version 1.4.0, Iobroker V5.12.5 send no "lastwill" out. The connected message works as aspected.

To Reproduce
Steps to reproduce the behavior:

  1. stop this adapter, or stop iobroker
  2. open MQTT Explorer and show this topic send or not
  3. connected works, lastwill not

Versions:

Thanks for this very good adapter! Greetings Thomas

Apollon77 commented 3 years ago

Please provide a debug level log of such a case ... last time I checked it it did send it out

ThomasLoeffel commented 3 years ago

I start and stop this adapter. MQTT Explorer send me "connected" but not "lastwill".

2021-09-23 22:32:23.819 - info: mqtt-client.0 (21812) Adapter is disabled => stop -- 2021-09-23 22:32:23.821 - info: mqtt-client.0 (21812) cleaned everything up... 2021-09-23 22:32:23.823 - info: host.iobroker-syn "system.adapter.mqtt-client.0" disabled 2021-09-23 22:32:23.827 - info: host.iobroker-syn stopInstance system.adapter.mqtt-client.0 (force=false, process=true) 2021-09-23 22:32:24.027 - info: mqtt-client.0 (21812) terminating 2021-09-23 22:32:24.027 - info: mqtt-client.0 (21812) Terminated (NO_ERROR): Without reason 2021-09-23 22:32:24.585 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 terminated with code 0 (NO_ERROR) 2021-09-23 22:32:24.585 - info: host.iobroker-syn Do not restart adapter system.adapter.mqtt-client.0 because disabled or deleted 2021-09-23 22:33:56.250 - info: host.iobroker-syn "system.adapter.mqtt-client.0" enabled 2021-09-23 22:33:56.391 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 started with pid 4249 2021-09-23 22:33:57.313 - info: mqtt-client.0 (4249) starting. Version 1.4.0 in /opt/iobroker/node_modules/iobroker.mqtt-client, node: v12.22.6, js-controller: 3.3.18 2021-09-23 22:33:57.418 - info: mqtt-client.0 (4249) enabled syncing of hm-rega.0.34265 (publish/subscribe:true/true) 2021-09-23 22:33:57.419 - info: mqtt-client.0 (4249) Try to connect to mqtt://mqtt:*******************@192.168.180.43:1883?clientId=iobroker with lwt "/iobroker/System" 2021-09-23 22:33:57.481 - info: mqtt-client.0 (4249) connected to broker 2021-09-23 22:34:42.793 - info: host.iobroker-syn "system.adapter.mqtt-client.0" disabled 2021-09-23 22:34:42.792 - info: mqtt-client.0 (4249) Adapter is disabled => stop 2021-09-23 22:34:42.796 - info: host.iobroker-syn stopInstance system.adapter.mqtt-client.0 (force=false, process=true) 2021-09-23 22:34:42.793 - info: mqtt-client.0 (4249) cleaned everything up... 2021-09-23 22:34:42.995 - info: mqtt-client.0 (4249) terminating 2021-09-23 22:34:42.996 - info: mqtt-client.0 (4249) Terminated (NO_ERROR): Without reason 2021-09-23 22:34:43.546 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 terminated with code 0 (NO_ERROR) 2021-09-23 22:34:43.547 - info: host.iobroker-syn Do not restart adapter system.adapter.mqtt-client.0 because disabled or deleted

Greetings Thomas

Apollon77 commented 3 years ago

Please use Admin - Instances - Expert mode - adjust loglevel to "Debug" and do it again. We need a casecovered by the log that would should contain the missing last will and ideally you provide more infos (simply think that the dev has no clue about mqtt ;-) ) The more details you can provide the easier it is possible to fix

ThomasLoeffel commented 3 years ago

Hello Ingo,

switched to "debug".

2021-09-24 12:24:05.824 - info: host.iobroker-syn "system.adapter.mqtt-client.0" enabled -- 2021-09-24 12:24:05.919 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 started with pid 11992 2021-09-24 12:24:06.767 - info: mqtt-client.0 (11992) starting. Version 1.4.0 in /opt/iobroker/node_modules/iobroker.mqtt-client, node: v12.22.6, js-controller: 3.3.18 2021-09-24 12:24:06.907 - info: mqtt-client.0 (11992) enabled syncing of hm-rega.0.34265 (publish/subscribe:true/true) 2021-09-24 12:24:06.908 - info: mqtt-client.0 (11992) Try to connect to mqtt://mqtt:*******************@192.168.180.43:1883?clientId=iobroker with lwt "/iobroker/System" 2021-09-24 12:24:06.971 - info: mqtt-client.0 (11992) connected to broker 2021-09-24 12:24:29.650 - info: mqtt-client.0 (11992) Adapter is disabled => stop 2021-09-24 12:24:29.650 - info: mqtt-client.0 (11992) cleaned everything up... 2021-09-24 12:24:29.657 - info: host.iobroker-syn "system.adapter.mqtt-client.0" disabled 2021-09-24 12:24:29.659 - info: host.iobroker-syn stopInstance system.adapter.mqtt-client.0 (force=false, process=true) 2021-09-24 12:24:29.855 - info: mqtt-client.0 (11992) terminating 2021-09-24 12:24:29.856 - info: mqtt-client.0 (11992) Terminated (NO_ERROR): Without reason 2021-09-24 12:24:30.435 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 terminated with code 0 (NO_ERROR) 2021-09-24 12:24:30.436 - info: host.iobroker-syn Do not restart adapter system.adapter.mqtt-client.0 because disabled or deleted 2021-09-24 12:29:15.084 - info: host.iobroker-syn "system.adapter.mqtt-client.0" enabled 2021-09-24 12:29:15.187 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 started with pid 18962 2021-09-24 12:29:15.630 - debug: mqtt-client.0 (18962) Redis Objects: Use Redis connection: 127.0.0.1:9001 2021-09-24 12:29:15.655 - debug: mqtt-client.0 (18962) Objects client ready ... initialize now 2021-09-24 12:29:15.656 - debug: mqtt-client.0 (18962) Objects create System PubSub Client 2021-09-24 12:29:15.657 - debug: mqtt-client.0 (18962) Objects create User PubSub Client 2021-09-24 12:29:15.658 - debug: mqtt-client.0 (18962) Objects client initialize lua scripts 2021-09-24 12:29:15.675 - debug: mqtt-client.0 (18962) Objects connected to redis: 127.0.0.1:9001 2021-09-24 12:29:15.682 - debug: mqtt-client.0 (18962) objectDB connected 2021-09-24 12:29:15.683 - debug: mqtt-client.0 (18962) Redis States: Use Redis connection: 127.0.0.1:6379 2021-09-24 12:29:15.689 - debug: mqtt-client.0 (18962) States create System PubSub Client 2021-09-24 12:29:15.689 - debug: mqtt-client.0 (18962) States create User PubSub Client 2021-09-24 12:29:15.694 - debug: mqtt-client.0 (18962) States connected to redis: 127.0.0.1:6379 2021-09-24 12:29:15.695 - debug: mqtt-client.0 (18962) statesDB connected 2021-09-24 12:29:15.855 - debug: mqtt-client.0 (18962) Plugin sentry Initialize Plugin (enabled=true) 2021-09-24 12:29:16.099 - info: mqtt-client.0 (18962) starting. Version 1.4.0 in /opt/iobroker/node_modules/iobroker.mqtt-client, node: v12.22.6, js-controller: 3.3.18 2021-09-24 12:29:16.256 - debug: mqtt-client.0 (18962) complete Custom: {"hm-rega.0.34265":{"enabled":true,"publish":true,"pubChangesOnly":false,"pubAsObject":false,"qos":0,"retain":false,"subscribe":true,"subChangesOnly":false,"subAsObject":false,"subQos":false,"setAck":false,"topic":"Homematic/Duty","type":"number"}} 2021-09-24 12:29:16.257 - info: mqtt-client.0 (18962) enabled syncing of hm-rega.0.34265 (publish/subscribe:true/true) 2021-09-24 12:29:16.257 - info: mqtt-client.0 (18962) Try to connect to mqtt://mqtt:*******************@192.168.180.43:1883?clientId=iobroker with lwt "/iobroker/System" 2021-09-24 12:29:16.303 - info: mqtt-client.0 (18962) connected to broker 2021-09-24 12:29:16.307 - debug: mqtt-client.0 (18962) subscribed to: {"Homematic/Duty":0} 2021-09-24 12:29:16.350 - debug: mqtt-client.0 (18962) succesfully published {"topic":"/iobroker/System","message":"bin online"} 2021-09-24 12:29:31.294 - info: mqtt-client.0 (18962) Adapter is disabled => stop 2021-09-24 12:29:31.295 - info: host.iobroker-syn "system.adapter.mqtt-client.0" disabled 2021-09-24 12:29:31.297 - info: host.iobroker-syn stopInstance system.adapter.mqtt-client.0 (force=false, process=true) 2021-09-24 12:29:31.295 - info: mqtt-client.0 (18962) cleaned everything up... 2021-09-24 12:29:31.499 - info: mqtt-client.0 (18962) terminating 2021-09-24 12:29:31.500 - debug: mqtt-client.0 (18962) Plugin sentry destroyed 2021-09-24 12:29:31.500 - info: mqtt-client.0 (18962) Terminated (NO_ERROR): Without reason 2021-09-24 12:29:32.095 - info: host.iobroker-syn instance system.adapter.mqtt-client.0 terminated with code 0 (NO_ERROR) 2021-09-24 12:29:32.095 - info: host.iobroker-syn Do not restart adapter system.adapter.mqtt-client.0 because disabled or deleted

Greetings Thomas

pmbert commented 2 years ago

Obviously there is a misunderstanding about the purpose and functionality of lastwill by the developer.

Quote from the documentation:

Der Server speichert diese Nachricht und sendet sie an seine Abonnenten, wenn der Client die Verbindung trennt.

The server does NOT send it when the client closes the connection regularly, but only in case of an error. In case of normal termination the client must send its own 'disconnected' message.

Quote from MQTT specification: When connecting to an event broker, MQTT clients may specify a "last will and testament" (or simply "will") message. A will message is stored with the MQTT session information that is allocated for the client, and is sent if an MQTT client is disconnected from the event broker **unexpectedly**.

The sentence in the client documentation is clearly wrong, and the behavior of the program probably is too.

I have also been able to verify this behavior with mosquitto.

Apollon77 commented 2 years ago

Uups, sorry I tagged wrong issue :-) (was issue #85 that got fixed)

Pmant commented 2 years ago

I don't think https://github.com/Pmant/ioBroker.mqtt-client/commit/29789bb40fe8623a07b736573f1ea2ab34ff81a2 solved the LWT issue. a) Documentation should point out LWT is only ever published when the client disconnects unexpectedly. b) To cover regular disconnects there should be a another option in adapter settings.

Apollon77 commented 2 years ago

@ThomasLoeffel Please install Github version using https://github.com/Pmant/ioBroker.mqtt-client#lwt_ondisconnect and give feedback if this works as expected ... So we can check that before merging the PR from @Pmant

Pmant commented 2 years ago

Actually use https://github.com/Pmant/ioBroker.mqtt-client/tree/lwt_ondisconnect as custom URL to install the PR version.