smarthomeNG/smarthome

mqtt: Reconnect failed

laraveluser opened this issue · 4 comments

I am a big fan of smarthomeNG. Unfortunately, since the upgrade to the latest version, the MQTT module regularly crashes. Always when the broker is restarted.

I was able to temporarily fix the problem for me by removing the reference to item in the _on_connect method in the module init:
"item = self._subscribed_topics[topic]"

self._subscribed_topics[topic] does not return an item, but topic_dict, which in turn does not contain an item object. Since I don't use qos, I just removed that.

def _on_connect(self, client, userdata, flags, rc):
    """
    Callback function called on connect
    """
    self._connect_result = mqtt.connack_string(rc)

    if rc == 0:
        self.logger.info("Connection returned result '{}' (userdata={}) ".format(mqtt.connack_string(rc), userdata))
        self._connected = True

        self._subscribe_broker_infos()

        # subscribe to topics to listen for items
        for topic in self._subscribed_topics:
            #item = self._subscribed_topics[topic]
            #self._client.subscribe(topic, qos=self._get_qos_forTopic(item))
            #self.logger.info("Listening on topic '{}' for item '{}'".format(topic, item.id()))
            self._client.subscribe(topic)

        self.logger.info("self._subscribed_topics = {}".format(self._subscribed_topics))

        return

    msg = "Connection returned result '{}': {} (client={}, userdata={}, self._client={})".format(str(rc), mqtt.connack_string(rc), client, userdata, self._client)
    if rc == 5:
        self.logger.error(msg)
        self._disconnect_from_broker()
    else:
        self.logger.warning(msg)

The same problem has the method "_disconnect_from_broker", but only for the logger.

It would be nice if the problem were solved a little more cleanly in a next update. I have not found a way to load the qos from the concrete item.

If this is not the right way to report problems and workarounds, please bear with me and let me know. This is my first post on github.

msinn commented

@laraveluser You wrote SmartHomeNG crashes. Could you post logs showing the crashes?

msinn commented

Fixed with commit 9f37ed0

msinn commented

SmartHomeNG v1.9.2 with the resolution has been released

@msinn No, unfortunately not. No error messages were displayed to me. I haven't had a chance to install the update yet. But I assume that the problem has been solved. Thank you very much!