MqttMonitor/MqttClient.py

changeset 30
17ef10819773
parent 24
b4e18aadc311
child 31
40582e448c4b
equal deleted inserted replaced
28:0f02baed8308 30:17ef10819773
158 @type bool 158 @type bool
159 """ 159 """
160 self.__mqttClient.will_set(topic, payload=payload, qos=qos, 160 self.__mqttClient.will_set(topic, payload=payload, qos=qos,
161 retain=retain) 161 retain=retain)
162 162
163 def clearLastWill(self):
164 """
165 Public method to remove a will that was previously configured with
166 setLastWill().
167 """
168 self.__mqttClient.will_clear()
169
163 def setTLS(self, caCerts=None, certFile=None, keyFile=None): 170 def setTLS(self, caCerts=None, certFile=None, keyFile=None):
164 """ 171 """
165 Public method to enable secure connections and set the TLS parameters. 172 Public method to enable secure connections and set the TLS parameters.
166 173
167 @param caCerts path to the Certificate Authority certificates file 174 @param caCerts path to the Certificate Authority certificates file
168 @type str 175 @type str
169 @param certFile PEM encoded client certificate file 176 @param certFile PEM encoded client certificate file
170 @type str 177 @type str
171 @param keyFile PEM encoded private key file 178 @param keyFile PEM encoded private key file
172 @type str 179 @type str
173 """ 180 @return tuple containing a success flag and the error string of the
174 self.__mqttClient.tls_set(ca_certs=caCerts, certfile=certFile, 181 paho-mqtt library
175 keyfile=keyFile) 182 @rtype tuple of (bool, str)
183 """
184 try:
185 self.__mqttClient.tls_set(ca_certs=caCerts, certfile=certFile,
186 keyfile=keyFile)
187 return True, ""
188 except ValueError as err:
189 return False, str(err)
176 190
177 def startLoop(self): 191 def startLoop(self):
178 """ 192 """
179 Public method to start the MQTT client loop. 193 Public method to start the MQTT client loop.
180 """ 194 """
202 @type int 216 @type int
203 @param bindAddress IP address of a local network interface to bind 217 @param bindAddress IP address of a local network interface to bind
204 this client to 218 this client to
205 @type str 219 @type str
206 """ 220 """
221 # TODO: get this fixed or allow to interrupt
222 self.__mqttClient.reconnect_delay_set(max_delay=16)
207 self.__mqttClient.connect_async( 223 self.__mqttClient.connect_async(
208 host, port=port, keepalive=keepalive, bind_address=bindAddress) 224 host, port=port, keepalive=keepalive, bind_address=bindAddress)
209 225
210 if not self.__loopStarted: 226 if not self.__loopStarted:
211 self.startLoop() 227 self.startLoop()

eric ide

mercurial