def init_app_mqtt_client()

in client/iot_client.py [0:0]


    def init_app_mqtt_client(self, init_listeners=True):
        """
        Initializes the MQTT client using credentials previously retrieved and store in the object

        :param init_listeners:
        Optionally disable the listeners for the MQTT client for debugging purposes

        :return:
        None
        """
        print("Connecting MQTT client")

        pk_pem = "\n".join(self.private_key_pem.decode('utf-8').splitlines())
        pk_file = tempfile.NamedTemporaryFile()
        pk_file.write(pk_pem.encode('utf-8'))
        pk_file.flush()

        cert_pem = "\n".join(self.certificate_pem.splitlines())
        cert_file = tempfile.NamedTemporaryFile()
        cert_file.write(cert_pem.encode('utf-8'))
        cert_file.flush()

        self.configureCredentials("AmazonRootCA1.pem", pk_file.name, cert_file.name)

        attempts = 0
        time.sleep(1)
        while attempts < 5:
            try:
                self.connect()
                print("MQTT client connected")
                break
            except connectTimeoutException:
                print("Connection timed out, trying again")
                attempts += 1
                continue
        else:
            print("Too many attempts")
            raise Exception

        if init_listeners:
            self.shadow_listener("default")
            print("Initialized shadow listener")

            self.init_jobs_client()
            print("IoT Client initialization completed")

        print("Reporting initial shadow")
        self.report_shadow(self.shadow, "default", False)