188 |
188 |
189 ####################################################################### |
189 ####################################################################### |
190 ## Slots handling MQTT related signals |
190 ## Slots handling MQTT related signals |
191 ####################################################################### |
191 ####################################################################### |
192 |
192 |
193 def __createClient(self, protocol=MqttProtocols.MQTTv311): |
193 # TODO: make MQTT default protocol version a configuration option |
|
194 # (config page) |
|
195 def __createClient(self, clientId="", cleanSession=None, |
|
196 protocol=MqttProtocols.MQTTv311): |
194 """ |
197 """ |
195 Private method to instantiate a MQTT client for a given protocol. |
198 Private method to instantiate a MQTT client for a given protocol. |
196 |
199 |
|
200 @param clientId ID to be used for the client |
|
201 @type str |
|
202 @param cleanSession flag indicating to start a clean session |
|
203 @type bool |
197 @param protocol MQTT protocol version to be used (defaults to |
204 @param protocol MQTT protocol version to be used (defaults to |
198 MqttProtocols.MQTTv311) |
205 MqttProtocols.MQTTv311) |
199 @type MqttProtocols (optional) |
206 @type MqttProtocols (optional) |
200 @return created and connected MQTT client object |
207 @return created and connected MQTT client object |
201 @rtype MqttClient |
208 @rtype MqttClient |
202 """ |
209 """ |
203 client = MqttClient(protocol=protocol) |
210 client = MqttClient(clientId=clientId, cleanSession=cleanSession, |
|
211 protocol=protocol) |
204 |
212 |
205 # connect the MQTT client signals |
213 # connect the MQTT client signals |
206 client.onConnect.connect(self.__brokerConnected) |
214 client.onConnect.connect(self.__brokerConnected) |
207 client.onDisconnected.connect(self.__brokerDisconnected) |
215 client.onDisconnected.connect(self.__brokerDisconnected) |
208 client.onLog.connect(self.__clientLog) |
216 client.onLog.connect(self.__clientLog) |
217 |
225 |
218 ####################################################################### |
226 ####################################################################### |
219 ## Slots handling MQTT related signals |
227 ## Slots handling MQTT related signals |
220 ####################################################################### |
228 ####################################################################### |
221 |
229 |
|
230 # TODO: change to accept ReasonCode for rc |
222 @pyqtSlot(dict, int) |
231 @pyqtSlot(dict, int) |
223 def __brokerConnected(self, flags, rc): |
232 def __brokerConnected(self, flags, rc): |
224 """ |
233 """ |
225 Private slot to handle being connected to a broker. |
234 Private slot to handle being connected to a broker. |
226 |
235 |
1044 if self.__connectionOptions is None: |
1053 if self.__connectionOptions is None: |
1045 self.__client = self.__createClient() |
1054 self.__client = self.__createClient() |
1046 self.__client.connectToServer(host, port=port) |
1055 self.__client.connectToServer(host, port=port) |
1047 else: |
1056 else: |
1048 self.__client = self.__createClient( |
1057 self.__client = self.__createClient( |
1049 protocol=self.__connectionOptions["Protocol"]) |
1058 clientId=self.__connectionOptions["ClientId"], |
|
1059 cleanSession=self.__connectionOptions["CleanSession"], |
|
1060 protocol=self.__connectionOptions["Protocol"] |
|
1061 ) |
1050 self.__client.connectToServerWithOptions( |
1062 self.__client.connectToServerWithOptions( |
1051 host, port=port, options=self.__connectionOptions) |
1063 host, port=port, options=self.__connectionOptions) |
1052 |
1064 |
1053 def __profileConnectToBroker(self): |
1065 def __profileConnectToBroker(self): |
1054 """ |
1066 """ |
1072 host, port)) |
1084 host, port)) |
1073 self.brokerStatusLabel.show() |
1085 self.brokerStatusLabel.show() |
1074 |
1086 |
1075 self.connectButton.setEnabled(False) |
1087 self.connectButton.setEnabled(False) |
1076 |
1088 |
1077 self.__client = self.__createClient(protocol=protocol) |
1089 self.__client = self.__createClient( |
|
1090 clientId=connectionProfile["ClientId"], |
|
1091 cleanSession=connectionProfile["CleanSession"], |
|
1092 protocol=protocol |
|
1093 ) |
1078 self.__client.connectToServerWithOptions( |
1094 self.__client.connectToServerWithOptions( |
1079 host, port=port, options=connectionProfile) |
1095 host, port=port, options=connectionProfile) |