--- a/MqttMonitor/MqttMonitorWidget.py Sun Jul 18 18:30:15 2021 +0200 +++ b/MqttMonitor/MqttMonitorWidget.py Sun Jul 18 19:32:16 2021 +0200 @@ -190,17 +190,25 @@ ## Slots handling MQTT related signals ####################################################################### - def __createClient(self, protocol=MqttProtocols.MQTTv311): + # TODO: make MQTT default protocol version a configuration option + # (config page) + def __createClient(self, clientId="", cleanSession=None, + protocol=MqttProtocols.MQTTv311): """ Private method to instantiate a MQTT client for a given protocol. + @param clientId ID to be used for the client + @type str + @param cleanSession flag indicating to start a clean session + @type bool @param protocol MQTT protocol version to be used (defaults to MqttProtocols.MQTTv311) @type MqttProtocols (optional) @return created and connected MQTT client object @rtype MqttClient """ - client = MqttClient(protocol=protocol) + client = MqttClient(clientId=clientId, cleanSession=cleanSession, + protocol=protocol) # connect the MQTT client signals client.onConnect.connect(self.__brokerConnected) @@ -219,6 +227,7 @@ ## Slots handling MQTT related signals ####################################################################### + # TODO: change to accept ReasonCode for rc @pyqtSlot(dict, int) def __brokerConnected(self, flags, rc): """ @@ -1046,7 +1055,10 @@ self.__client.connectToServer(host, port=port) else: self.__client = self.__createClient( - protocol=self.__connectionOptions["Protocol"]) + clientId=self.__connectionOptions["ClientId"], + cleanSession=self.__connectionOptions["CleanSession"], + protocol=self.__connectionOptions["Protocol"] + ) self.__client.connectToServerWithOptions( host, port=port, options=self.__connectionOptions) @@ -1074,6 +1086,10 @@ self.connectButton.setEnabled(False) - self.__client = self.__createClient(protocol=protocol) + self.__client = self.__createClient( + clientId=connectionProfile["ClientId"], + cleanSession=connectionProfile["CleanSession"], + protocol=protocol + ) self.__client.connectToServerWithOptions( host, port=port, options=connectionProfile)