simpkins / de1plus-mqtt

MQTT plugin for Decent Espresso machines
Other
21 stars 0 forks source link

Plugin does not send Home Assistant auto-discovery messages #1

Closed wulfithewulf closed 7 months ago

wulfithewulf commented 8 months ago

My system is as follows:

I installed the plugin on the decent and configured it as described in the docs. I also disabled all battery saving functions I could find.

Issue: The HA auto-discovery messages were not published to the broker. I checked that by subscribing to topic "homeassistant/#" on the broker.

I manipulated the code (as others in the diaspora did), that the messages would be send regardless of connection state in the method on_con_event:

proc on_conn_event {topic data retain} {
        variable current_status
        # Republish our status each time we reconnect
        msg "received conn event: $data"
        if {[dict get $data state] eq "connected"} {
            msg "connected"
            # Publishing directly inside a CONNACK event callback unfortunately
            # doesn't work, since the mqtt library hasn't stored the fd yet,
            # and it just drops the publish message.  Therefore use an after
            # call to schedule this publish.
            after 1 ::plugins::mqtt::post_connect_publish
            set current_status "Connected"
        } else {
            # The mqtt package unfortunately does not deliver connection events
            # to us with the TCP connection is refused.  We only mostly only
            # get connection events after the connection is established and the
            # server sends a CONNACK packet.  Therefore on TCP connect errors
            # our current_status will unfortunately just remain as
            # "Connecting..." in most cases.
            msg "connection status: $data"

            after 1 ::plugins::mqtt::post_connect_publish
            msg "not connected but running post_connect_publish anyway"
            switch -- [dict get $data reason] {
              0 {set reason_str "Connection Accepted"}
              1 {set reason_str "Unaccepted MQTT Protocol Version"}
              2 {set reason_str "Client ID Rejected"}
              3 {set reason_str "Server Unavailable"}
              4 {set reason_str "Bad Username or Password"}
              5 {set reason_str "Client Not Authorized"}
              default {set reason_str "MQTT code $data(reason)"}
            }
            set current_status "[dict get $data state]: $reason_str"
            msg "connection status: $current_status"
        }
    }

But that did not work. I also didn't see the loggings from this function in the log. It seems, that this method is never called. Nonetheless the plugin started to publish status messages.

I then added the line after 1 ::plugins::mqtt::post_connect_publish at the end of start_client, which worked. After that I removed the line again.

simpkins commented 7 months ago

I finally got around to taking a look at this. The issue appears to be caused by a newer version of the tcl mqtt package that is shipped with newer versions of Androwish. If your tablet is using a newer version of Androwish it will come with version 3.1 of the tcl mqtt package, while older tablets have version 2.0.

The newer mqtt package adds support for MQTT 5.0, and also made some minor changes to how connection status is reported. The plugin.tcl file did not work with these updates to how connection status is reported.

This should be fixed now in commit d01575a6bea84552d83028c447d0f0886a4811e2.