From 328d3471a748472695a61193becdda76c7eefe69 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 11 Feb 2024 10:27:31 +0100 Subject: [PATCH] Adaption to 2.0 API --- __init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/__init__.py b/__init__.py index 2ac9de1..88118d4 100644 --- a/__init__.py +++ b/__init__.py @@ -51,7 +51,7 @@ class mqtt_client(object): self.__block_add_callbacks__ = True logger.info("Initiating mqtt client instance") self.__callbacks__ = {} - self.__client__ = paho.Client(name) # create client object + self.__client__ = paho.Client(paho.CallbackAPIVersion.VERSION2) # create client object if username is not None and password is not None: logger.debug("Configuring authentification") self.__client__.username_pw_set(username, password) # login with credentials @@ -59,7 +59,7 @@ class mqtt_client(object): self.__client__.on_connect = self.__on_connect__ self.__client__.on_disconnect = self.__on_disconnect__ try: - self.__client__.connect(host, port) # establish connection + self.__client__.connect(host, port, 60) # establish connection except (socket.timeout, OSError) as e: logger.warning("Can not connect to MQTT-Server") self.__client__.loop_start() # start the loop @@ -75,8 +75,8 @@ class mqtt_client(object): get_topic_logger(topic).debug("Sending message with topic %s and payload %s", topic, str(payload)) self.__client__.publish(topic, payload) - def __on_connect__(self, client, userdata, flags, rc): - logger.debug("Connect with rc=%d", rc) + def __on_connect__(self, client, userdata, flags, rc, properties): + logger.debug("Connect with rc=%s", repr(rc)) if rc == 0: self.__block_add_callbacks__ = True logger.debug("Registering topics...") @@ -84,8 +84,8 @@ class mqtt_client(object): self.__client__.subscribe(topic) self.__block_add_callbacks__ = False - def __on_disconnect__(self, client, flags, rc): - logger.warning("Disconnect with rc=%d", rc) + def __on_disconnect__(self, client, userdata, flags, rc, properties): + logger.warning("Disconnect with rc=%s", repr(rc)) def __receive__(self, client, userdata, message): get_topic_logger(message.topic).debug("Received message with topic %s and payload %s", message.topic, str(message.payload))