MqttMonitor/MqttClient.py

changeset 30
17ef10819773
parent 24
b4e18aadc311
child 31
40582e448c4b
diff -r 0f02baed8308 -r 17ef10819773 MqttMonitor/MqttClient.py
--- a/MqttMonitor/MqttClient.py	Sat Sep 08 16:55:42 2018 +0200
+++ b/MqttMonitor/MqttClient.py	Sun Sep 09 12:21:19 2018 +0200
@@ -160,6 +160,13 @@
         self.__mqttClient.will_set(topic, payload=payload, qos=qos,
                                    retain=retain)
     
+    def clearLastWill(self):
+        """
+        Public method to remove a will that was previously configured with
+        setLastWill().
+        """
+        self.__mqttClient.will_clear()
+    
     def setTLS(self, caCerts=None, certFile=None, keyFile=None):
         """
         Public method to enable secure connections and set the TLS parameters.
@@ -170,9 +177,16 @@
         @type str
         @param keyFile PEM encoded private key file
         @type str
+        @return tuple containing a success flag and the error string of the
+            paho-mqtt library
+        @rtype tuple of (bool, str)
         """
-        self.__mqttClient.tls_set(ca_certs=caCerts, certfile=certFile,
-                                  keyfile=keyFile)
+        try:
+            self.__mqttClient.tls_set(ca_certs=caCerts, certfile=certFile,
+                                      keyfile=keyFile)
+            return True, ""
+        except ValueError as err:
+            return False, str(err)
     
     def startLoop(self):
         """
@@ -204,6 +218,8 @@
             this client to
         @type str
         """
+        # TODO: get this fixed or allow to interrupt
+        self.__mqttClient.reconnect_delay_set(max_delay=16)
         self.__mqttClient.connect_async(
             host, port=port, keepalive=keepalive, bind_address=bindAddress)
         

eric ide

mercurial