30 |
30 |
31 class MqttClient(QObject): |
31 class MqttClient(QObject): |
32 """ |
32 """ |
33 Class implementing a PyQt wrapper around the paho MQTT client. |
33 Class implementing a PyQt wrapper around the paho MQTT client. |
34 |
34 |
35 @signal onConnect(flags, rc) emitted after the client has connected to the |
35 @signal onConnectV3(flags, rc) emitted after the client has connected to |
36 broker |
36 the broker |
37 @signal onDisconnected(rc) emitted after the client has disconnected from |
37 @signal onDisconnectedV3(rc) emitted after the client has disconnected from |
38 the broker |
38 the broker |
39 @signal onLog(level, message) emitted to send client log data |
39 @signal onLog(level, message) emitted to send client log data |
40 @signal onMessage(topic, payload, qos, retain) emitted after a message has |
40 @signal onMessageV3(topic, payload, qos, retain) emitted after a message |
41 been received by the client |
41 has been received by the client |
42 @signal onPublish(mid) emitted after a message has been published |
42 @signal onPublish(mid) emitted after a message has been published |
43 @signal onSubscribe(mid, grantedQos) emitted after the client has |
43 @signal onSubscribeV3(mid, grantedQos) emitted after the client has |
44 subscribed to some topics |
44 subscribed to some topics |
45 @signal onUnsubscribe(mid) emitted after the client has unsubscribed from |
45 @signal onUnsubscribeV3(mid) emitted after the client has unsubscribed from |
46 some topics |
46 some topics |
47 @signal connectTimeout() emitted to indicate, that a connection attempt |
47 @signal connectTimeout() emitted to indicate, that a connection attempt |
48 timed out |
48 timed out |
49 """ |
49 """ |
50 onConnectV3 = pyqtSignal(dict, int) |
50 onConnectV3 = pyqtSignal(dict, int) |
51 onConnectV5 = pyqtSignal(dict, int, int) |
51 onConnectV5 = pyqtSignal(dict, int, int) |
52 onDisconnectedV3 = pyqtSignal(int) |
52 onDisconnectedV3 = pyqtSignal(int) |
53 onDisconnectedV5 = pyqtSignal(int, int) |
53 onDisconnectedV5 = pyqtSignal(int, int) |
54 onLog = pyqtSignal(int, str) |
54 onLog = pyqtSignal(int, str) |
55 onMessageV3 = pyqtSignal(str, bytes, int, bool) |
55 onMessageV3 = pyqtSignal(str, bytes, int, bool) |
56 onMessageV5 = pyqtSignal(str, bytes, int, bool) |
56 onMessageV5 = pyqtSignal(str, bytes, int, bool, dict) |
57 onPublish = pyqtSignal(int) |
57 onPublish = pyqtSignal(int) |
58 onSubscribeV3 = pyqtSignal(int, tuple) |
58 onSubscribeV3 = pyqtSignal(int, tuple) |
59 onSubscribeV5 = pyqtSignal(int, list) |
59 onSubscribeV5 = pyqtSignal(int, list) |
60 onUnsubscribeV3 = pyqtSignal(int) |
60 onUnsubscribeV3 = pyqtSignal(int) |
61 onUnsubscribeV5 = pyqtSignal(int, int, int) |
61 onUnsubscribeV5 = pyqtSignal(int, int, int) |
134 self.onConnectV3.emit(flags, rc) |
134 self.onConnectV3.emit(flags, rc) |
135 ) |
135 ) |
136 self.__mqttClient.on_disconnect = ( |
136 self.__mqttClient.on_disconnect = ( |
137 lambda client, userdata, rc: |
137 lambda client, userdata, rc: |
138 self.onDisconnectedV3.emit(rc) |
138 self.onDisconnectedV3.emit(rc) |
139 ) |
139 ) |
140 self.__mqttClient.on_subscribe = ( |
140 self.__mqttClient.on_subscribe = ( |
141 lambda client, userdata, mid, grantedQos, properties=None: |
141 lambda client, userdata, mid, grantedQos, properties=None: |
142 self.onSubscribeV3.emit(mid, grantedQos) |
142 self.onSubscribeV3.emit(mid, grantedQos) |
143 ) |
143 ) |
144 self.__mqttClient.on_unsubscribe = ( |
144 self.__mqttClient.on_unsubscribe = ( |
166 self.onUnsubscribeV5.emit(mid, rc.value, rc.packetType) |
166 self.onUnsubscribeV5.emit(mid, rc.value, rc.packetType) |
167 ) |
167 ) |
168 self.__mqttClient.on_message = ( |
168 self.__mqttClient.on_message = ( |
169 lambda client, userdata, message: |
169 lambda client, userdata, message: |
170 self.onMessageV5.emit(message.topic, message.payload, |
170 self.onMessageV5.emit(message.topic, message.payload, |
171 message.qos, message.retain) |
171 message.qos, message.retain, |
|
172 message.properties.json()) |
172 ) |
173 ) |
173 self.__mqttClient.on_log = ( |
174 self.__mqttClient.on_log = ( |
174 lambda client, userdata, level, buf: |
175 lambda client, userdata, level, buf: |
175 self.onLog.emit(level, buf) |
176 self.onLog.emit(level, buf) |
176 ) |
177 ) |