mstoffel-sag / c8yMQTT

Python3 Cumulocity Agent implementation for MQTT and Rasperry PI
13 stars 8 forks source link

Connect sequence is not correct #4

Closed ts4iot closed 4 years ago

ts4iot commented 4 years ago

The condition in file: c8yMQTT.py, line 115) is not correct:

Current code:

        count=0
        while self.connected==False and  count < 50: 
            time.sleep(.2)
            count+=1
        if self.connected!=False:
            self.logger.error('Could not connect to the MQTT Broker.')
            return False
        else:
            self.client.loop_start()
            for t in topics:
                self.client.subscribe(t, 2)

Suggested change:

        count=0
        self.client.loop_start()
        while self.connected==False and  count < 50: 
            time.sleep(.2)
            count+=1
        if self.connected==False:
            self.logger.error('Could not connect to the MQTT Broker.')
            self.client.loop_stop()
            return False
        else:
            for t in topics:
                self.client.subscribe(t, 2)
mstoffel-sag commented 4 years ago

Sorry for the late reply. This should be solved in Release v0.2 since it uses more robust connection mechanisms.