MqttMonitor/MqttClient.py

Thu, 06 Sep 2018 19:34:49 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 06 Sep 2018 19:34:49 +0200
branch
connection_profiles
changeset 22
545979c7dcd4
parent 11
90d3ebed4cc0
child 24
b4e18aadc311
permissions
-rw-r--r--

MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.

2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de>
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a PyQt wrapper around the paho MQTT client.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtCore import pyqtSignal, QObject, QCoreApplication
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import paho.mqtt.client as mqtt
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
22
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11
diff changeset
16 from Utilities.crypto import pwConvert
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11
diff changeset
17
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class MqttClient(QObject):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing a PyQt wrapper around the paho MQTT client.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @signal onConnect(flags, rc) emitted after the client has connected to the
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @signal onDisconnected(rc) emitted after the client has disconnected from
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 the broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @signal onMessage(topic, payload, qos, retain) emitted after a message has
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 been received by the client
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @signal onPublish(mid) emitted after a message has been published
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @signal onSubscribe(mid, grantedQos) emitted after the client has
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 subscribed to some topics
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @signal onUnsubscribe(mid) emitted after the client has unsubscribed from
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 some topics
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 onConnect = pyqtSignal(dict, int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 onDisconnected = pyqtSignal(int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 onMessage = pyqtSignal(str, bytes, int, bool)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 onPublish = pyqtSignal(int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 onSubscribe = pyqtSignal(int, tuple)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 onUnsubscribe = pyqtSignal(int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 def __init__(self, clientId="", cleanSession=True, userdata=None,
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 protocol=mqtt.MQTTv311, transport="tcp", parent=None):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 Constructor
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param clientId ID to be used for the client
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param cleanSession flag indicating to start a clean session
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @type bool
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @param userdata user data
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @type any
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @param protocol version of the MQTT protocol to use
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @type int, one of mqtt.MQTTv31 or mqtt.MQTTv311
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @param transport transport to be used
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @type str, one of "tcp" or "websockets"
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param parent reference to the parent object
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @type QObject
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 QObject.__init__(self, parent=parent)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__loopStarted = False
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.__mqttClient = mqtt.Client(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 client_id=clientId, clean_session=cleanSession, userdata=None,
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 protocol=mqtt.MQTTv311, transport="tcp")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
68 self.__initCallbacks()
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
69
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
70 def __initCallbacks(self):
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
71 """
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
72 Private method to initialize the MQTT callback methods.
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
73 """
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.__mqttClient.on_connect = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 lambda client, userdata, flags, rc: self.onConnect.emit(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 flags, rc)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__mqttClient.on_disconnect = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 lambda client, userdata, rc: self.onDisconnected.emit(rc)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__mqttClient.on_message = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 lambda client, userdata, message: self.onMessage.emit(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 message.topic, message.payload, message.qos, message.retain)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__mqttClient.on_publish = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 lambda client, userdata, mid: self.onPublish.emit(mid)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.__mqttClient.on_subscribe = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 lambda client, userdata, mid, grantedQos: self.onSubscribe.emit(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 mid, grantedQos)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__mqttClient.on_unsubscribe = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 lambda client, userdata, mid: self.onUnsubscribe.emit(mid)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
90 def reinitialise(self, clientId="", cleanSession=True, userdata=None):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
91 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
92 Public method to reinitialize the client with given data.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
93
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
94 @param clientId ID to be used for the client
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
95 @type str
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
96 @param cleanSession flag indicating to start a clean session
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
97 @type bool
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
98 @param userdata user data
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
99 @type any
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
100 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
101 self.__mqttClient.reinitialise(
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
102 client_id=clientId, clean_session=cleanSession, userdata=userdata)
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
103
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
104 self.__initCallbacks()
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
105
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
106 def setMaxInflightMessages(self, inflight=20):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
107 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
108 Public method to set the maximum number of messages with QoS > 0 that
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
109 can be part way through their network flow at once.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
110
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
111 @param inflight maximum number of messages in flight
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
112 @type int
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
113 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
114 self.__mqttClient.max_inflight_messages_set(inflight)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
115
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
116 def setMaxQueuedMessages(self, queueSize=0):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
117 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
118 Public method to set the maximum number of messages with QoS > 0 that
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
119 can be pending in the outgoing message queue.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
120
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
121 @param queueSize maximum number of queued messages (0 = unlimited)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
122 @type int
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
123 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
124 self.__mqttClient.max_queued_messages_set(queueSize)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
125
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
126 def setUserCredentials(self, username, password=None):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
127 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
128 Public method to set the user name and optionally the password.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
129
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
130 @param username user name to be set
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
131 @type str
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
132 @param password optional password
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
133 @type str
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
134 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
135 self.__mqttClient.username_pw_set(username, password=password)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
136
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
137 def setUserData(self, userdata):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
138 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
139 Public method to set the user data.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
140
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
141 @param userdata user data
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
142 @type any
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
143 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
144 self.__mqttClient.user_data_set(userdata)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
145
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
146 def setLastWill(self, topic, payload=None, qos=0, retain=False):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
147 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
148 Public method to set the last will of the client.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
149
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
150 @param topic topic the will message should be published on
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
151 @type str
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
152 @param payload message to send as a will
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
153 @type str, bytes, int or float
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
154 @param qos quality of service level to use for the will
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
155 @type int, one of 0, 1 or 2
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
156 @param retain flag indicating to set as the "last known good"/retained
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
157 message for the will topic
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
158 @type bool
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
159 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
160 self.__mqttClient.will_set(topic, payload=payload, qos=qos,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
161 retain=retain)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
162
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 def startLoop(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 Public method to start the MQTT client loop.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 self.__mqttClient.loop_start()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self.__loopStarted = True
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 def stopLoop(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 Public method to stop the MQTT client loop.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.__mqttClient.loop_stop()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 self.__loopStarted = False
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 def connectToServer(self, host, port=1883, keepalive=60, bindAddress=""):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 Public method to connect to a remote MQTT broker.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @param host host name or IP address of the remote broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @param port network port of the server host to connect to (default:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 1883, using TLS: 8883)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 @type int
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @param keepalive maximum period in seconds allowed between
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 communications with the broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @type int
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @param bindAddress IP address of a local network interface to bind
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 this client to
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.__mqttClient.connect_async(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 host, port=port, keepalive=keepalive, bind_address=bindAddress)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 if not self.__loopStarted:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.startLoop()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
199 def connectToServerWithOptions(self, host, port=1883, bindAddress="",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
200 options=None):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
201 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
202 Public method to connect to a remote MQTT broker.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
203
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
204 @param host host name or IP address of the remote broker
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
205 @type str
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
206 @param port network port of the server host to connect to (default:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
207 1883, using TLS: 8883)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
208 @type int
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
209 @param bindAddress IP address of a local network interface to bind
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
210 this client to
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
211 @type str
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
212 @param options dictionary containing the connection options. This
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
213 dictionary should contain the keys "ClientId", "Keepalive",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
214 "CleanSession", "Username", "Password", "WillTopic", "WillMessage",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
215 "WillQos", "WillRetain"
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
216 @type dict
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
217 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
218 if options:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
219 parametersDict = self.defaultConnectionOptions()
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
220 parametersDict.update(options)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
221
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
222 # step 1: reinitialize to set the client ID and clean session flag
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
223 self.reinitialise(
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
224 clientId=parametersDict["ClientId"],
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
225 cleanSession=parametersDict["CleanSession"]
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
226 )
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
227
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
228 # step 2: set username and password
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
229 if parametersDict["Username"]:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
230 if parametersDict["Password"]:
22
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11
diff changeset
231 self.setUserCredentials(
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11
diff changeset
232 parametersDict["Username"],
545979c7dcd4 MqttClient, MqttConnectionOptionsDialog: added support for encrypted passwords.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 11
diff changeset
233 pwConvert(parametersDict["Password"], encode=False))
10
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
234 else:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
235 self.setUserCredentials(parametersDict["Username"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
236
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
237 # step 3: set last will data
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
238 if parametersDict["WillTopic"]:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
239 if parametersDict["WillMessage"]:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
240 willMessage = parametersDict["WillMessage"]
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
241 else:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
242 # empty message to clear the will
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
243 willMessage = None
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
244 self.setLastWill(parametersDict["WillTopic"],
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
245 willMessage,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
246 parametersDict["WillQos"],
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
247 parametersDict["WillRetain"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
248
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
249 # step 4: connect to server
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
250 self.connectToServer(host, port=port,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
251 keepalive=parametersDict["Keepalive"])
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
252 else:
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
253 keepalive = self.defaultConnectionOptions["Keepalive"]
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
254 self.connectToServer(host, port=port, keepalive=keepalive,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
255 bindAddress=bindAddress)
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
256
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
257 def defaultConnectionOptions(self):
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
258 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
259 Public method to get a connection options dictionary with default
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
260 values.
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
261
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
262 @return dictionary containing the default connection options. It has
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
263 the keys "ClientId", "Keepalive", "CleanSession", "Username",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
264 "Password", "WillTopic", "WillMessage", "WillQos", "WillRetain"
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
265 @rtype dict
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
266 """
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
267 return {
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
268 "ClientId": "ERIC6_MQTT_MONITOR_CLIENT",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
269 "Keepalive": 60,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
270 "CleanSession": True,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
271 "Username": "",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
272 "Password": "",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
273 "WillTopic": "",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
274 "WillMessage": "",
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
275 "WillQos": 0,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
276 "WillRetain": False,
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
277 }
7e0e921dc7ea Started to implement the connection options dialog and methods to specify these connection options connecting to the server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9
diff changeset
278
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 def reconnectToServer(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 Public method to reconnect the client with the same parameters.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 self.__mqttClient.reconnect()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 if not self.__loopStarted:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 self.startLoop()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 def disconnectFromServer(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 Public method to disconnect the client from the remote broker.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 self.__mqttClient.disconnect()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 def subscribe(self, topic, qos=0):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 Public method to subscribe to topics with quality of service.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 @param topic single topic to subscribe to or a tuple with a topic
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 and a QoS or a list of tuples with a topic and a QoS each
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 @type str or tuple of (str, int) or list of tuple of (str, int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 @param qos quality of service
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 @type int, one of 0, 1 or 2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 @return tuple containing the result code and the message ID
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 @rtype tuple of (int, int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 return self.__mqttClient.subscribe(topic, qos=qos)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 def unsubscribe(self, topic):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 Public method to unsubscribe topics.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 @param topic topic or list of topics to unsubscribe
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 @type str or list of str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 @return tuple containing the result code and the message ID
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 @rtype tuple of (int, int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 return self.__mqttClient.unsubscribe(topic)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 def publish(self, topic, payload=None, qos=0, retain=False):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 Public method to publish to a topic.
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 @param topic topic to publish to
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 @param payload data to be published
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 @type str, bytes, int or float
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 @param qos quality of service
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 @type int, one of 0, 1 or 2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @param retain flag indicating to set as the "last known good"/retained
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 message for the topic
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 @type bool
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 @return message info object
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 @rtype mqtt.MQTTMessageInfo
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 return self.__mqttClient.publish(topic, payload=payload, qos=qos,
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 retain=retain)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
338
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 def mqttConnackMessage(connackCode):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 Public method to get the string associated with a CONNACK result.
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
342
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
343 @param connackCode result code of the connection request
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
344 @type int
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
345 @return textual representation for the result code
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
346 @rtype str
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 if connackCode == mqtt.CONNACK_ACCEPTED:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
350 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 "Connection Accepted.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 elif connackCode == mqtt.CONNACK_REFUSED_PROTOCOL_VERSION:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
354 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 "Connection Refused: unacceptable protocol version.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 elif connackCode == mqtt.CONNACK_REFUSED_IDENTIFIER_REJECTED:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
358 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 "Connection Refused: identifier rejected.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 elif connackCode == mqtt.CONNACK_REFUSED_SERVER_UNAVAILABLE:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
362 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 "Connection Refused: broker unavailable.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 elif connackCode == mqtt.CONNACK_REFUSED_BAD_USERNAME_PASSWORD:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
366 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 "Connection Refused: bad user name or password.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 elif connackCode == mqtt.CONNACK_REFUSED_NOT_AUTHORIZED:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
370 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 "Connection Refused: not authorised.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 else:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
374 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 "Connection Refused: unknown reason.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
377
9
f75a385e9127 MqttClient: fixed an issue in mqttErrorMessage() definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3
diff changeset
378 def mqttErrorMessage(mqttErrno):
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 Public method to get the error string associated with an MQTT error
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 number.
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
382
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
383 @param mqttErrno result code of a MQTT request
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
384 @type int
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
385 @return textual representation of the result code
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
386 @rtype str
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 if mqttErrno == mqtt.MQTT_ERR_SUCCESS:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
390 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 "No error.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 elif mqttErrno == mqtt.MQTT_ERR_NOMEM:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
394 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 "Out of memory.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 elif mqttErrno == mqtt.MQTT_ERR_PROTOCOL:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
398 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 "A network protocol error occurred when communicating with"
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 " the broker.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 elif mqttErrno == mqtt.MQTT_ERR_INVAL:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
403 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 "Invalid function arguments provided.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 elif mqttErrno == mqtt.MQTT_ERR_NO_CONN:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
407 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 "The client is not currently connected.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 elif mqttErrno == mqtt.MQTT_ERR_CONN_REFUSED:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
411 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 "The connection was refused.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 elif mqttErrno == mqtt.MQTT_ERR_NOT_FOUND:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
415 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 "Message not found (internal error).")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 elif mqttErrno == mqtt.MQTT_ERR_CONN_LOST:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
419 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 "The connection was lost.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 elif mqttErrno == mqtt.MQTT_ERR_TLS:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
423 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 "A TLS error occurred.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 elif mqttErrno == mqtt.MQTT_ERR_PAYLOAD_SIZE:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
427 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 "Payload too large.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 elif mqttErrno == mqtt.MQTT_ERR_NOT_SUPPORTED:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
431 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 "This feature is not supported.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 elif mqttErrno == mqtt.MQTT_ERR_AUTH:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
435 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 "Authorisation failed.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 elif mqttErrno == mqtt.MQTT_ERR_ACL_DENIED:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
439 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 "Access denied by ACL.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 elif mqttErrno == mqtt.MQTT_ERR_UNKNOWN:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
443 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 "Unknown error.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 elif mqttErrno == mqtt.MQTT_ERR_ERRNO:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
447 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 "Error defined by errno.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 else:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 return QCoreApplication.translate(
3
82845c0fd550 Fixed some code style issues and implemented the broker connect/disconnect group of the MqttMonitorWidget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2
diff changeset
451 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 "Unknown error.")

eric ide

mercurial