src/wiotp/sdk/client.py
def _onConnect(self, mqttc, userdata, flags, rc):
        """
        Called when the broker responds to our connection request.

        The value of rc determines success or not:
            0: Connection successful
            1: Connection refused - incorrect protocol version
            2: Connection refused - invalid client identifier
            3: Connection refused - server unavailable
            4: Connection refused - bad username or password
            5: Connection refused - not authorised
            6-255: Currently unused.
        """
        if rc == 0:
            self.connectEvent.set()
            self.logger.info("Connected successfully: %s" % (self.clientId))

            # Restoring previous subscriptions
            with self._subLock:
                if len(self._subscriptions) > 0:
                    for subscription in self._subscriptions:
                        # We use the underlying mqttclient subscribe method rather than _subscribe because we are
                        # claiming a lock on the subscriptions list and do not want anything else to modify it,
                        # which that method does
                        (result, mid) = self.client.subscribe(subscription, qos=self._subscriptions[subscription])
                        if result != paho.MQTT_ERR_SUCCESS:
                            self._logAndRaiseException(ConnectionException("Unable to subscribe to %s" % subscription))
                    self.logger.debug("Restored %s previous subscriptions" % len(self._subscriptions))
        elif rc == 1:
            self._logAndRaiseException(ConnectionException("Incorrect protocol version"))
        elif rc == 2:
            self._logAndRaiseException(ConnectionException("Invalid client identifier"))
        elif rc == 3:
            self._logAndRaiseException(ConnectionException("Server unavailable"))
        elif rc == 4:
            self._logAndRaiseException(
                ConnectionException("Bad username or password: (%s, %s)" % (self.username, self.password))
            )
        elif rc == 5:
            self._logAndRaiseException(
                ConnectionException("Not authorized: s (%s, %s, %s)" % (self.clientId, self.username, self.password))
            )
        else:
            self._logAndRaiseException(ConnectionException("Unexpected connection failure: %s" % (rc)))
def _onConnect(self, mqttc, userdata, flags, rc):
        if rc == 0:
            self.connectEvent.set()
            self.logger.info("Connected successfully: %s" % (self.clientId))

            # Restoring previous subscriptions
            with self._subLock:
                if len(self._subscriptions) > 0:
                    for subscription in self._subscriptions:
                        # We use the underlying mqttclient subscribe method rather than _subscribe because we are
                        # claiming a lock on the subscriptions list and do not want anything else to modify it,
                        # which that method does
                        (result, mid) = self.client.subscribe(subscription, qos=self._subscriptions[subscription])
                        if result != paho.MQTT_ERR_SUCCESS:
                            self._logAndRaiseException(ConnectionException("Unable to subscribe to %s" % subscription))
                    self.logger.debug("Restored %s previous subscriptions" % len(self._subscriptions))
        elif rc == 1:
            self._logAndRaiseException(ConnectionException("Incorrect protocol version"))
        elif rc == 2:
            self._logAndRaiseException(ConnectionException("Invalid client identifier"))
        elif rc == 3:
            self._logAndRaiseException(ConnectionException("Server unavailable"))
        elif rc == 4:
            self._logAndRaiseException(
                ConnectionException("Bad username or password: (%s, %s)" % (self.username, self.password))
            )
        elif rc == 5:
            self._logAndRaiseException(
                ConnectionException("Not authorized: s (%s, %s, %s)" % (self.clientId, self.username, self.password))
            )
        else:
            self._logAndRaiseException(ConnectionException("Unexpected connection failure: %s" % (rc)))
def _onConnect ( self , mqttc , userdata , flags , rc ) : if rc == 0 : self . connectEvent . set ( ) self . logger . info ( "Connected successfully: %s" % ( self . clientId ) ) # Restoring previous subscriptions with self . _subLock : if len ( self . _subscriptions ) > 0 : for subscription in self . _subscriptions : # We use the underlying mqttclient subscribe method rather than _subscribe because we are # claiming a lock on the subscriptions list and do not want anything else to modify it, # which that method does ( result , mid ) = self . client . subscribe ( subscription , qos = self . _subscriptions [ subscription ] ) if result != paho . MQTT_ERR_SUCCESS : self . _logAndRaiseException ( ConnectionException ( "Unable to subscribe to %s" % subscription ) ) self . logger . debug ( "Restored %s previous subscriptions" % len ( self . _subscriptions ) ) elif rc == 1 : self . _logAndRaiseException ( ConnectionException ( "Incorrect protocol version" ) ) elif rc == 2 : self . _logAndRaiseException ( ConnectionException ( "Invalid client identifier" ) ) elif rc == 3 : self . _logAndRaiseException ( ConnectionException ( "Server unavailable" ) ) elif rc == 4 : self . _logAndRaiseException ( ConnectionException ( "Bad username or password: (%s, %s)" % ( self . username , self . password ) ) ) elif rc == 5 : self . _logAndRaiseException ( ConnectionException ( "Not authorized: s (%s, %s, %s)" % ( self . clientId , self . username , self . password ) ) ) else : self . _logAndRaiseException ( ConnectionException ( "Unexpected connection failure: %s" % ( rc ) ) )
Called when the broker responds to our connection request.

        The value of rc determines success or not:
            0: Connection successful
            1: Connection refused - incorrect protocol version
            2: Connection refused - invalid client identifier
            3: Connection refused - server unavailable
            4: Connection refused - bad username or password
            5: Connection refused - not authorised
            6-255: Currently unused.
Called when the broker responds to our connection request .