in rpi-image-builder/aws-iot-fleet-provisioning/provisioning_handler.py [0:0]
def core_connect(self):
""" Method used to connect to AWS IoTCore Service. Endpoint collected from config.
"""
if self.isRotation:
self.logger.info('##### CONNECTING WITH EXISTING CERT #####')
print('##### CONNECTING WITH EXISTING CERT #####')
self.get_current_certs()
else:
self.logger.info('##### CONNECTING WITH PROVISIONING CLAIM CERT #####')
print('##### CONNECTING WITH PROVISIONING CLAIM CERT #####')
event_loop_group = io.EventLoopGroup(1)
host_resolver = io.DefaultHostResolver(event_loop_group)
client_bootstrap = io.ClientBootstrap(event_loop_group, host_resolver)
self.primary_MQTTClient = mqtt_connection_builder.mtls_from_path(
endpoint=self.iot_endpoint,
cert_filepath="{}/{}".format(self.secure_cert_path, self.claim_cert),
pri_key_filepath="{}/{}".format(self.secure_cert_path, self.secure_key),
client_bootstrap=client_bootstrap,
ca_filepath="{}/{}".format(self.secure_cert_path, self.root_cert),
on_connection_interrupted=self.on_connection_interrupted,
on_connection_resumed=self.on_connection_resumed,
client_id=self.unique_id,
clean_session=False,
keep_alive_secs=6)
print("Connecting to {} with client ID '{}'...".format(self.iot_endpoint, self.unique_id))
connect_future = self.primary_MQTTClient.connect()
# Future.result() waits until a result is available
connect_future.result()
print("Connected!")