|
@@ -51,7 +51,7 @@ class mqtt_client(object):
|
51
|
51
|
self.__block_add_callbacks__ = True
|
52
|
52
|
logger.info("Initiating mqtt client instance")
|
53
|
53
|
self.__callbacks__ = {}
|
54
|
|
- self.__client__ = paho.Client(name) # create client object
|
|
54
|
+ self.__client__ = paho.Client(paho.CallbackAPIVersion.VERSION2) # create client object
|
55
|
55
|
if username is not None and password is not None:
|
56
|
56
|
logger.debug("Configuring authentification")
|
57
|
57
|
self.__client__.username_pw_set(username, password) # login with credentials
|
|
@@ -59,7 +59,7 @@ class mqtt_client(object):
|
59
|
59
|
self.__client__.on_connect = self.__on_connect__
|
60
|
60
|
self.__client__.on_disconnect = self.__on_disconnect__
|
61
|
61
|
try:
|
62
|
|
- self.__client__.connect(host, port) # establish connection
|
|
62
|
+ self.__client__.connect(host, port, 60) # establish connection
|
63
|
63
|
except (socket.timeout, OSError) as e:
|
64
|
64
|
logger.warning("Can not connect to MQTT-Server")
|
65
|
65
|
self.__client__.loop_start() # start the loop
|
|
@@ -75,8 +75,8 @@ class mqtt_client(object):
|
75
|
75
|
get_topic_logger(topic).debug("Sending message with topic %s and payload %s", topic, str(payload))
|
76
|
76
|
self.__client__.publish(topic, payload)
|
77
|
77
|
|
78
|
|
- def __on_connect__(self, client, userdata, flags, rc):
|
79
|
|
- logger.debug("Connect with rc=%d", rc)
|
|
78
|
+ def __on_connect__(self, client, userdata, flags, rc, properties):
|
|
79
|
+ logger.debug("Connect with rc=%s", repr(rc))
|
80
|
80
|
if rc == 0:
|
81
|
81
|
self.__block_add_callbacks__ = True
|
82
|
82
|
logger.debug("Registering topics...")
|
|
@@ -84,8 +84,8 @@ class mqtt_client(object):
|
84
|
84
|
self.__client__.subscribe(topic)
|
85
|
85
|
self.__block_add_callbacks__ = False
|
86
|
86
|
|
87
|
|
- def __on_disconnect__(self, client, flags, rc):
|
88
|
|
- logger.warning("Disconnect with rc=%d", rc)
|
|
87
|
+ def __on_disconnect__(self, client, userdata, flags, rc, properties):
|
|
88
|
+ logger.warning("Disconnect with rc=%s", repr(rc))
|
89
|
89
|
|
90
|
90
|
def __receive__(self, client, userdata, message):
|
91
|
91
|
get_topic_logger(message.topic).debug("Received message with topic %s and payload %s", message.topic, str(message.payload))
|