code: def reconnect(self, cleansession=None):
          
  
          if self.session.transitions.is_connected():
              self.logger.warning("Client already connected")
              return CONNECTION_ACCEPTED
  
          if cleansession:
              self.session.clean_session = cleansession
          self.logger.debug("Reconnecting with session parameters: %s" % self.session)
          reconnect_max_interval = self.config.get('reconnect_max_interval', 10)
          reconnect_retries = self.config.get('reconnect_retries', 5)
          nb_attempt = 1
          yield from asyncio.sleep(1, loop=self._loop)
          while True:
              try:
                  self.logger.debug("Reconnect attempt %d ..." % nb_attempt)
                  return (yield from self._do_connect())
              except BaseException as e:
                  self.logger.warning("Reconnection attempt failed: %r" % e)
                  if reconnect_retries >= 0 and nb_attempt > reconnect_retries:
                      self.logger.error("Maximum number of connection attempts reached. Reconnection aborted")
                      raise ConnectException("Too many connection attempts failed")
                  exp = 2 ** nb_attempt
                  delay = exp if exp < reconnect_max_interval else reconnect_max_interval
                  self.logger.debug("Waiting %d second before next attempt" % delay)
                  yield from asyncio.sleep(delay, loop=self._loop)
                  nb_attempt += 1
docs: Reconnect a previously connected broker.
  
              Reconnection tries to establish a network connection and send a `CONNECT <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718028>`_ message.
              Retries interval and attempts can be controled with the ``reconnect_max_interval`` and ``reconnect_retries`` configuration parameters.
  
              This method is a *coroutine*.
  
              :param cleansession: clean session flag used in MQTT CONNECT messages sent for reconnections.
              :return: `CONNACK <http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718033>`_ return code
              :raise: :class:`hbmqtt.client.ConnectException` if re-connection fails after max retries.