MqttMonitor/MqttClient.py

Sun, 02 Sep 2018 18:29:35 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Sep 2018 18:29:35 +0200
changeset 11
90d3ebed4cc0
parent 10
7e0e921dc7ea
child 22
545979c7dcd4
permissions
-rw-r--r--

Finished implementing the connection options dialog.

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
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class MqttClient(QObject):
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 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
20
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @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
22 broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @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
24 the broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @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
26 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
27 @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
28 @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
29 subscribed to some topics
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @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
31 some topics
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 onConnect = pyqtSignal(dict, int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 onDisconnected = pyqtSignal(int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 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
36 onPublish = pyqtSignal(int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 onSubscribe = pyqtSignal(int, tuple)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 onUnsubscribe = pyqtSignal(int)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 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
41 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
42 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Constructor
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 @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
46 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @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
48 @type bool
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param userdata user data
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @type any
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @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
52 @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
53 @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
54 @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
55 @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
56 @type QObject
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 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
59
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__loopStarted = False
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.__mqttClient = mqtt.Client(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 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
64 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
65
11
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
66 self.__initCallbacks()
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
67
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
68 def __initCallbacks(self):
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 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
71 """
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__mqttClient.on_connect = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 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
74 flags, rc)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__mqttClient.on_disconnect = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 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
77 self.__mqttClient.on_message = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 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
79 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
80 self.__mqttClient.on_publish = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 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
82 self.__mqttClient.on_subscribe = \
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, grantedQos: self.onSubscribe.emit(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 mid, grantedQos)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__mqttClient.on_unsubscribe = \
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 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
87
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
88 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
89 """
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 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
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 @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
93 @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
94 @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
95 @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
96 @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
97 @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
98 """
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 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
100 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
101
90d3ebed4cc0 Finished implementing the connection options dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
102 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
103
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
104 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
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 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
107 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
108
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 @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
110 @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
111 """
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 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
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 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
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 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
117 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
118
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 @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
120 @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
121 """
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 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
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 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
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 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
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 @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
129 @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
130 @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
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 """
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 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
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 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
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 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
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 @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
140 @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
141 """
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 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
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 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
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 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
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 @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
149 @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
150 @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
151 @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
152 @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
153 @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
154 @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
155 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
156 @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
157 """
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 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
159 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
160
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 def startLoop(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 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
164 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.__mqttClient.loop_start()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__loopStarted = True
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 def stopLoop(self):
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 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
171 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.__mqttClient.loop_stop()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.__loopStarted = False
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 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
176 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 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
178
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @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
180 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @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
182 1883, using TLS: 8883)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @type int
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @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
185 communications with the broker
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @type int
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 @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
188 this client to
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.__mqttClient.connect_async(
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 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
193
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 if not self.__loopStarted:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.startLoop()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
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
197 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
198 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
199 """
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 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
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 @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
203 @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
204 @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
205 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
206 @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
207 @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
208 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
209 @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
210 @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
211 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
212 "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
213 "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
214 @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
215 """
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 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
217 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
218 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
219
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 # 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
221 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
222 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
223 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
224 )
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
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 # 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
227 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
228 if parametersDict["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 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
230 parametersDict["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
231 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
232 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
233
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 # 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
235 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
236 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
237 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
238 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
239 # 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
240 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
241 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
242 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
243 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
244 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
245
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 # 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
247 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
248 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
249 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
250 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
251 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
252 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
253
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 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
255 """
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 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
257 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
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 @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
260 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
261 "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
262 @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
263 """
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 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
265 "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
266 "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
267 "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
268 "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
269 "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
270 "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
271 "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
272 "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
273 "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
274 }
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
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 def reconnectToServer(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 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
279 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 self.__mqttClient.reconnect()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 if not self.__loopStarted:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 self.startLoop()
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 def disconnectFromServer(self):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 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
288 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 self.__mqttClient.disconnect()
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 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
292 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 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
294
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 @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
296 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
297 @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
298 @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
299 @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
300 @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
301 @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
302 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 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
304
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 def unsubscribe(self, topic):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 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
308
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 @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
310 @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
311 @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
312 @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
313 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 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
315
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 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
317 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 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
319
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 @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
321 @type str
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 @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
323 @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
324 @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
325 @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
326 @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
327 message for the topic
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 @type bool
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @return message info object
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 @rtype mqtt.MQTTMessageInfo
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 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
333 retain=retain)
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334
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
335
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 def mqttConnackMessage(connackCode):
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 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
339
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
340 @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
341 @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
342 @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
343 @rtype str
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 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
346 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
347 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 "Connection Accepted.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 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
350 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
351 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 "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
353 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
354 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
355 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 "Connection Refused: identifier rejected.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 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
358 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
359 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 "Connection Refused: broker unavailable.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 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
362 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
363 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 "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
365 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
366 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
367 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 "Connection Refused: not authorised.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 else:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 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
371 "MqttConnackMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 "Connection Refused: unknown reason.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373
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
9
f75a385e9127 MqttClient: fixed an issue in mqttErrorMessage() definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3
diff changeset
375 def mqttErrorMessage(mqttErrno):
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 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
378 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
379
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
380 @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
381 @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
382 @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
383 @rtype str
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 """
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 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
386 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
387 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 "No error.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 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
390 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
391 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 "Out of memory.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 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
394 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
395 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 "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
397 " the broker.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 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
399 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
400 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 "Invalid function arguments provided.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 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
403 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
404 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 "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
406 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
407 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
408 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 "The connection was refused.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 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
411 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
412 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 "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
414 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
415 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
416 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 "The connection was lost.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 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
419 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
420 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 "A TLS error occurred.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 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
423 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
424 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 "Payload too large.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 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
427 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
428 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 "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
430 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
431 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
432 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 "Authorisation failed.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 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
435 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
436 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 "Access denied by ACL.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 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
439 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
440 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 "Unknown error.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 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
443 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
444 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 "Error defined by errno.")
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 else:
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 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
448 "MqttErrorMessage",
2
d439c5109829 MqttClient: added the MqttClient wrapper around paho.mqtt.client.Client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 "Unknown error.")

eric ide

mercurial