|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>Plugin_Mqtt_Monitor.MqttMonitor.MqttClient</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>Plugin_Mqtt_Monitor.MqttMonitor.MqttClient</h1> |
|
23 <p> |
|
24 Module implementing a PyQt wrapper around the paho MQTT client. |
|
25 </p> |
|
26 <h3>Global Attributes</h3> |
|
27 <table> |
|
28 <tr><td>None</td></tr> |
|
29 </table> |
|
30 <h3>Classes</h3> |
|
31 <table> |
|
32 <tr> |
|
33 <td><a href="#MqttClient">MqttClient</a></td> |
|
34 <td>Class implementing a PyQt wrapper around the paho MQTT client.</td> |
|
35 </tr> |
|
36 </table> |
|
37 <h3>Functions</h3> |
|
38 <table> |
|
39 <tr> |
|
40 <td><a href="#mqttConnackMessage">mqttConnackMessage</a></td> |
|
41 <td>Public method to get the string associated with a CONNACK result.</td> |
|
42 </tr><tr> |
|
43 <td><a href="#mqttErrorMessage">mqttErrorMessage</a></td> |
|
44 <td>Public method to get the error string associated with an MQTT error number.</td> |
|
45 </tr> |
|
46 </table> |
|
47 <hr /><hr /> |
|
48 <a NAME="MqttClient" ID="MqttClient"></a> |
|
49 <h2>MqttClient</h2> |
|
50 <p> |
|
51 Class implementing a PyQt wrapper around the paho MQTT client. |
|
52 </p><h3>Signals</h3> |
|
53 <dl> |
|
54 <dt>onConnect(flags, rc)</dt> |
|
55 <dd> |
|
56 emitted after the client has connected to the |
|
57 broker |
|
58 </dd><dt>onDisconnected(rc)</dt> |
|
59 <dd> |
|
60 emitted after the client has disconnected from |
|
61 the broker |
|
62 </dd><dt>onMessage(topic, payload, qos, retain)</dt> |
|
63 <dd> |
|
64 emitted after a message has |
|
65 been received by the client |
|
66 </dd><dt>onPublish(mid)</dt> |
|
67 <dd> |
|
68 emitted after a message has been published |
|
69 </dd><dt>onSubscribe(mid, grantedQos)</dt> |
|
70 <dd> |
|
71 emitted after the client has |
|
72 subscribed to some topics |
|
73 </dd><dt>onUnsubscribe(mid)</dt> |
|
74 <dd> |
|
75 emitted after the client has unsubscribed from |
|
76 some topics |
|
77 </dd> |
|
78 </dl> |
|
79 <h3>Derived from</h3> |
|
80 QObject |
|
81 <h3>Class Attributes</h3> |
|
82 <table> |
|
83 <tr><td>None</td></tr> |
|
84 </table> |
|
85 <h3>Class Methods</h3> |
|
86 <table> |
|
87 <tr><td>None</td></tr> |
|
88 </table> |
|
89 <h3>Methods</h3> |
|
90 <table> |
|
91 <tr> |
|
92 <td><a href="#MqttClient.__init__">MqttClient</a></td> |
|
93 <td>Constructor</td> |
|
94 </tr><tr> |
|
95 <td><a href="#MqttClient.__initCallbacks">__initCallbacks</a></td> |
|
96 <td>Private method to initialize the MQTT callback methods.</td> |
|
97 </tr><tr> |
|
98 <td><a href="#MqttClient.connectToServer">connectToServer</a></td> |
|
99 <td>Public method to connect to a remote MQTT broker.</td> |
|
100 </tr><tr> |
|
101 <td><a href="#MqttClient.connectToServerWithOptions">connectToServerWithOptions</a></td> |
|
102 <td>Public method to connect to a remote MQTT broker.</td> |
|
103 </tr><tr> |
|
104 <td><a href="#MqttClient.defaultConnectionOptions">defaultConnectionOptions</a></td> |
|
105 <td>Public method to get a connection options dictionary with default values.</td> |
|
106 </tr><tr> |
|
107 <td><a href="#MqttClient.disconnectFromServer">disconnectFromServer</a></td> |
|
108 <td>Public method to disconnect the client from the remote broker.</td> |
|
109 </tr><tr> |
|
110 <td><a href="#MqttClient.publish">publish</a></td> |
|
111 <td>Public method to publish to a topic.</td> |
|
112 </tr><tr> |
|
113 <td><a href="#MqttClient.reconnectToServer">reconnectToServer</a></td> |
|
114 <td>Public method to reconnect the client with the same parameters.</td> |
|
115 </tr><tr> |
|
116 <td><a href="#MqttClient.reinitialise">reinitialise</a></td> |
|
117 <td>Public method to reinitialize the client with given data.</td> |
|
118 </tr><tr> |
|
119 <td><a href="#MqttClient.setLastWill">setLastWill</a></td> |
|
120 <td>Public method to set the last will of the client.</td> |
|
121 </tr><tr> |
|
122 <td><a href="#MqttClient.setMaxInflightMessages">setMaxInflightMessages</a></td> |
|
123 <td>Public method to set the maximum number of messages with QoS > 0 that can be part way through their network flow at once.</td> |
|
124 </tr><tr> |
|
125 <td><a href="#MqttClient.setMaxQueuedMessages">setMaxQueuedMessages</a></td> |
|
126 <td>Public method to set the maximum number of messages with QoS > 0 that can be pending in the outgoing message queue.</td> |
|
127 </tr><tr> |
|
128 <td><a href="#MqttClient.setUserCredentials">setUserCredentials</a></td> |
|
129 <td>Public method to set the user name and optionally the password.</td> |
|
130 </tr><tr> |
|
131 <td><a href="#MqttClient.setUserData">setUserData</a></td> |
|
132 <td>Public method to set the user data.</td> |
|
133 </tr><tr> |
|
134 <td><a href="#MqttClient.startLoop">startLoop</a></td> |
|
135 <td>Public method to start the MQTT client loop.</td> |
|
136 </tr><tr> |
|
137 <td><a href="#MqttClient.stopLoop">stopLoop</a></td> |
|
138 <td>Public method to stop the MQTT client loop.</td> |
|
139 </tr><tr> |
|
140 <td><a href="#MqttClient.subscribe">subscribe</a></td> |
|
141 <td>Public method to subscribe to topics with quality of service.</td> |
|
142 </tr><tr> |
|
143 <td><a href="#MqttClient.unsubscribe">unsubscribe</a></td> |
|
144 <td>Public method to unsubscribe topics.</td> |
|
145 </tr> |
|
146 </table> |
|
147 <h3>Static Methods</h3> |
|
148 <table> |
|
149 <tr><td>None</td></tr> |
|
150 </table> |
|
151 <a NAME="MqttClient.__init__" ID="MqttClient.__init__"></a> |
|
152 <h4>MqttClient (Constructor)</h4> |
|
153 <b>MqttClient</b>(<i>clientId="", cleanSession=True, userdata=None, protocol=mqtt.MQTTv311, transport="tcp", parent=None</i>) |
|
154 <p> |
|
155 Constructor |
|
156 </p><dl> |
|
157 <dt><i>clientId</i> (str)</dt> |
|
158 <dd> |
|
159 ID to be used for the client |
|
160 </dd><dt><i>cleanSession</i> (bool)</dt> |
|
161 <dd> |
|
162 flag indicating to start a clean session |
|
163 </dd><dt><i>userdata</i> (any)</dt> |
|
164 <dd> |
|
165 user data |
|
166 </dd><dt><i>protocol</i> (int, one of mqtt.MQTTv31 or mqtt.MQTTv311)</dt> |
|
167 <dd> |
|
168 version of the MQTT protocol to use |
|
169 </dd><dt><i>transport</i> (str, one of "tcp" or "websockets")</dt> |
|
170 <dd> |
|
171 transport to be used |
|
172 </dd><dt><i>parent</i> (QObject)</dt> |
|
173 <dd> |
|
174 reference to the parent object |
|
175 </dd> |
|
176 </dl><a NAME="MqttClient.__initCallbacks" ID="MqttClient.__initCallbacks"></a> |
|
177 <h4>MqttClient.__initCallbacks</h4> |
|
178 <b>__initCallbacks</b>(<i></i>) |
|
179 <p> |
|
180 Private method to initialize the MQTT callback methods. |
|
181 </p><a NAME="MqttClient.connectToServer" ID="MqttClient.connectToServer"></a> |
|
182 <h4>MqttClient.connectToServer</h4> |
|
183 <b>connectToServer</b>(<i>host, port=1883, keepalive=60, bindAddress=""</i>) |
|
184 <p> |
|
185 Public method to connect to a remote MQTT broker. |
|
186 </p><dl> |
|
187 <dt><i>host</i> (str)</dt> |
|
188 <dd> |
|
189 host name or IP address of the remote broker |
|
190 </dd><dt><i>port</i> (int)</dt> |
|
191 <dd> |
|
192 network port of the server host to connect to (default: |
|
193 1883, using TLS: 8883) |
|
194 </dd><dt><i>keepalive</i> (int)</dt> |
|
195 <dd> |
|
196 maximum period in seconds allowed between |
|
197 communications with the broker |
|
198 </dd><dt><i>bindAddress</i> (str)</dt> |
|
199 <dd> |
|
200 IP address of a local network interface to bind |
|
201 this client to |
|
202 </dd> |
|
203 </dl><a NAME="MqttClient.connectToServerWithOptions" ID="MqttClient.connectToServerWithOptions"></a> |
|
204 <h4>MqttClient.connectToServerWithOptions</h4> |
|
205 <b>connectToServerWithOptions</b>(<i>host, port=1883, bindAddress="", options=None</i>) |
|
206 <p> |
|
207 Public method to connect to a remote MQTT broker. |
|
208 </p><dl> |
|
209 <dt><i>host</i> (str)</dt> |
|
210 <dd> |
|
211 host name or IP address of the remote broker |
|
212 </dd><dt><i>port</i> (int)</dt> |
|
213 <dd> |
|
214 network port of the server host to connect to (default: |
|
215 1883, using TLS: 8883) |
|
216 </dd><dt><i>bindAddress</i> (str)</dt> |
|
217 <dd> |
|
218 IP address of a local network interface to bind |
|
219 this client to |
|
220 </dd><dt><i>options</i> (dict)</dt> |
|
221 <dd> |
|
222 dictionary containing the connection options. This |
|
223 dictionary should contain the keys "ClientId", "Keepalive", |
|
224 "CleanSession", "Username", "Password", "WillTopic", "WillMessage", |
|
225 "WillQos", "WillRetain" |
|
226 </dd> |
|
227 </dl><a NAME="MqttClient.defaultConnectionOptions" ID="MqttClient.defaultConnectionOptions"></a> |
|
228 <h4>MqttClient.defaultConnectionOptions</h4> |
|
229 <b>defaultConnectionOptions</b>(<i></i>) |
|
230 <p> |
|
231 Public method to get a connection options dictionary with default |
|
232 values. |
|
233 </p><dl> |
|
234 <dt>Returns:</dt> |
|
235 <dd> |
|
236 dictionary containing the default connection options. It has |
|
237 the keys "ClientId", "Keepalive", "CleanSession", "Username", |
|
238 "Password", "WillTopic", "WillMessage", "WillQos", "WillRetain" |
|
239 </dd> |
|
240 </dl><dl> |
|
241 <dt>Return Type:</dt> |
|
242 <dd> |
|
243 dict |
|
244 </dd> |
|
245 </dl><a NAME="MqttClient.disconnectFromServer" ID="MqttClient.disconnectFromServer"></a> |
|
246 <h4>MqttClient.disconnectFromServer</h4> |
|
247 <b>disconnectFromServer</b>(<i></i>) |
|
248 <p> |
|
249 Public method to disconnect the client from the remote broker. |
|
250 </p><a NAME="MqttClient.publish" ID="MqttClient.publish"></a> |
|
251 <h4>MqttClient.publish</h4> |
|
252 <b>publish</b>(<i>topic, payload=None, qos=0, retain=False</i>) |
|
253 <p> |
|
254 Public method to publish to a topic. |
|
255 </p><dl> |
|
256 <dt><i>topic</i> (str)</dt> |
|
257 <dd> |
|
258 topic to publish to |
|
259 </dd><dt><i>payload</i> (str, bytes, int or float)</dt> |
|
260 <dd> |
|
261 data to be published |
|
262 </dd><dt><i>qos</i> (int, one of 0, 1 or 2)</dt> |
|
263 <dd> |
|
264 quality of service |
|
265 </dd><dt><i>retain</i> (bool)</dt> |
|
266 <dd> |
|
267 flag indicating to set as the "last known good"/retained |
|
268 message for the topic |
|
269 </dd> |
|
270 </dl><dl> |
|
271 <dt>Returns:</dt> |
|
272 <dd> |
|
273 message info object |
|
274 </dd> |
|
275 </dl><dl> |
|
276 <dt>Return Type:</dt> |
|
277 <dd> |
|
278 mqtt.MQTTMessageInfo |
|
279 </dd> |
|
280 </dl><a NAME="MqttClient.reconnectToServer" ID="MqttClient.reconnectToServer"></a> |
|
281 <h4>MqttClient.reconnectToServer</h4> |
|
282 <b>reconnectToServer</b>(<i></i>) |
|
283 <p> |
|
284 Public method to reconnect the client with the same parameters. |
|
285 </p><a NAME="MqttClient.reinitialise" ID="MqttClient.reinitialise"></a> |
|
286 <h4>MqttClient.reinitialise</h4> |
|
287 <b>reinitialise</b>(<i>clientId="", cleanSession=True, userdata=None</i>) |
|
288 <p> |
|
289 Public method to reinitialize the client with given data. |
|
290 </p><dl> |
|
291 <dt><i>clientId</i> (str)</dt> |
|
292 <dd> |
|
293 ID to be used for the client |
|
294 </dd><dt><i>cleanSession</i> (bool)</dt> |
|
295 <dd> |
|
296 flag indicating to start a clean session |
|
297 </dd><dt><i>userdata</i> (any)</dt> |
|
298 <dd> |
|
299 user data |
|
300 </dd> |
|
301 </dl><a NAME="MqttClient.setLastWill" ID="MqttClient.setLastWill"></a> |
|
302 <h4>MqttClient.setLastWill</h4> |
|
303 <b>setLastWill</b>(<i>topic, payload=None, qos=0, retain=False</i>) |
|
304 <p> |
|
305 Public method to set the last will of the client. |
|
306 </p><dl> |
|
307 <dt><i>topic</i> (str)</dt> |
|
308 <dd> |
|
309 topic the will message should be published on |
|
310 </dd><dt><i>payload</i> (str, bytes, int or float)</dt> |
|
311 <dd> |
|
312 message to send as a will |
|
313 </dd><dt><i>qos</i> (int, one of 0, 1 or 2)</dt> |
|
314 <dd> |
|
315 quality of service level to use for the will |
|
316 </dd><dt><i>retain</i> (bool)</dt> |
|
317 <dd> |
|
318 flag indicating to set as the "last known good"/retained |
|
319 message for the will topic |
|
320 </dd> |
|
321 </dl><a NAME="MqttClient.setMaxInflightMessages" ID="MqttClient.setMaxInflightMessages"></a> |
|
322 <h4>MqttClient.setMaxInflightMessages</h4> |
|
323 <b>setMaxInflightMessages</b>(<i>inflight=20</i>) |
|
324 <p> |
|
325 Public method to set the maximum number of messages with QoS > 0 that |
|
326 can be part way through their network flow at once. |
|
327 </p><dl> |
|
328 <dt><i>inflight</i> (int)</dt> |
|
329 <dd> |
|
330 maximum number of messages in flight |
|
331 </dd> |
|
332 </dl><a NAME="MqttClient.setMaxQueuedMessages" ID="MqttClient.setMaxQueuedMessages"></a> |
|
333 <h4>MqttClient.setMaxQueuedMessages</h4> |
|
334 <b>setMaxQueuedMessages</b>(<i>queueSize=0</i>) |
|
335 <p> |
|
336 Public method to set the maximum number of messages with QoS > 0 that |
|
337 can be pending in the outgoing message queue. |
|
338 </p><dl> |
|
339 <dt><i>queueSize</i> (int)</dt> |
|
340 <dd> |
|
341 maximum number of queued messages (0 = unlimited) |
|
342 </dd> |
|
343 </dl><a NAME="MqttClient.setUserCredentials" ID="MqttClient.setUserCredentials"></a> |
|
344 <h4>MqttClient.setUserCredentials</h4> |
|
345 <b>setUserCredentials</b>(<i>username, password=None</i>) |
|
346 <p> |
|
347 Public method to set the user name and optionally the password. |
|
348 </p><dl> |
|
349 <dt><i>username</i> (str)</dt> |
|
350 <dd> |
|
351 user name to be set |
|
352 </dd><dt><i>password</i> (str)</dt> |
|
353 <dd> |
|
354 optional password |
|
355 </dd> |
|
356 </dl><a NAME="MqttClient.setUserData" ID="MqttClient.setUserData"></a> |
|
357 <h4>MqttClient.setUserData</h4> |
|
358 <b>setUserData</b>(<i>userdata</i>) |
|
359 <p> |
|
360 Public method to set the user data. |
|
361 </p><dl> |
|
362 <dt><i>userdata</i> (any)</dt> |
|
363 <dd> |
|
364 user data |
|
365 </dd> |
|
366 </dl><a NAME="MqttClient.startLoop" ID="MqttClient.startLoop"></a> |
|
367 <h4>MqttClient.startLoop</h4> |
|
368 <b>startLoop</b>(<i></i>) |
|
369 <p> |
|
370 Public method to start the MQTT client loop. |
|
371 </p><a NAME="MqttClient.stopLoop" ID="MqttClient.stopLoop"></a> |
|
372 <h4>MqttClient.stopLoop</h4> |
|
373 <b>stopLoop</b>(<i></i>) |
|
374 <p> |
|
375 Public method to stop the MQTT client loop. |
|
376 </p><a NAME="MqttClient.subscribe" ID="MqttClient.subscribe"></a> |
|
377 <h4>MqttClient.subscribe</h4> |
|
378 <b>subscribe</b>(<i>topic, qos=0</i>) |
|
379 <p> |
|
380 Public method to subscribe to topics with quality of service. |
|
381 </p><dl> |
|
382 <dt><i>topic</i> (str or tuple of (str, int) or list of tuple of (str, int))</dt> |
|
383 <dd> |
|
384 single topic to subscribe to or a tuple with a topic |
|
385 and a QoS or a list of tuples with a topic and a QoS each |
|
386 </dd><dt><i>qos</i> (int, one of 0, 1 or 2)</dt> |
|
387 <dd> |
|
388 quality of service |
|
389 </dd> |
|
390 </dl><dl> |
|
391 <dt>Returns:</dt> |
|
392 <dd> |
|
393 tuple containing the result code and the message ID |
|
394 </dd> |
|
395 </dl><dl> |
|
396 <dt>Return Type:</dt> |
|
397 <dd> |
|
398 tuple of (int, int) |
|
399 </dd> |
|
400 </dl><a NAME="MqttClient.unsubscribe" ID="MqttClient.unsubscribe"></a> |
|
401 <h4>MqttClient.unsubscribe</h4> |
|
402 <b>unsubscribe</b>(<i>topic</i>) |
|
403 <p> |
|
404 Public method to unsubscribe topics. |
|
405 </p><dl> |
|
406 <dt><i>topic</i> (str or list of str)</dt> |
|
407 <dd> |
|
408 topic or list of topics to unsubscribe |
|
409 </dd> |
|
410 </dl><dl> |
|
411 <dt>Returns:</dt> |
|
412 <dd> |
|
413 tuple containing the result code and the message ID |
|
414 </dd> |
|
415 </dl><dl> |
|
416 <dt>Return Type:</dt> |
|
417 <dd> |
|
418 tuple of (int, int) |
|
419 </dd> |
|
420 </dl> |
|
421 <div align="right"><a href="#top">Up</a></div> |
|
422 <hr /><hr /> |
|
423 <a NAME="mqttConnackMessage" ID="mqttConnackMessage"></a> |
|
424 <h2>mqttConnackMessage</h2> |
|
425 <b>mqttConnackMessage</b>(<i>connackCode</i>) |
|
426 <p> |
|
427 Public method to get the string associated with a CONNACK result. |
|
428 </p><dl> |
|
429 <dt><i>connackCode</i> (int)</dt> |
|
430 <dd> |
|
431 result code of the connection request |
|
432 </dd> |
|
433 </dl><dl> |
|
434 <dt>Returns:</dt> |
|
435 <dd> |
|
436 textual representation for the result code |
|
437 </dd> |
|
438 </dl><dl> |
|
439 <dt>Return Type:</dt> |
|
440 <dd> |
|
441 str |
|
442 </dd> |
|
443 </dl> |
|
444 <div align="right"><a href="#top">Up</a></div> |
|
445 <hr /><hr /> |
|
446 <a NAME="mqttErrorMessage" ID="mqttErrorMessage"></a> |
|
447 <h2>mqttErrorMessage</h2> |
|
448 <b>mqttErrorMessage</b>(<i>mqttErrno</i>) |
|
449 <p> |
|
450 Public method to get the error string associated with an MQTT error |
|
451 number. |
|
452 </p><dl> |
|
453 <dt><i>mqttErrno</i> (int)</dt> |
|
454 <dd> |
|
455 result code of a MQTT request |
|
456 </dd> |
|
457 </dl><dl> |
|
458 <dt>Returns:</dt> |
|
459 <dd> |
|
460 textual representation of the result code |
|
461 </dd> |
|
462 </dl><dl> |
|
463 <dt>Return Type:</dt> |
|
464 <dd> |
|
465 str |
|
466 </dd> |
|
467 </dl> |
|
468 <div align="right"><a href="#top">Up</a></div> |
|
469 <hr /> |
|
470 </body></html> |