in SubTemplates/IoT/Lambdas/provision_device/client/provisioning_handler.py [0:0]
def __init__(self, file_path):
"""Initializes the provisioning handler
Arguments:
file_path {string} -- path to your configuration file
"""
#Logging
logging.basicConfig(level=logging.ERROR)
self.logger = logging.getLogger(__name__)
#Load configuration settings from config.ini
config = Config(file_path)
self.config_parameters = config.get_section('SETTINGS')
self.secure_cert_path = self.config_parameters['SECURE_CERT_PATH']
self.iot_endpoint = self.config_parameters['IOT_ENDPOINT']
self.template_name = self.config_parameters['PRODUCTION_TEMPLATE']
self.rotation_template = self.config_parameters['CERT_ROTATION_TEMPLATE']
self.claim_cert = self.config_parameters['CLAIM_CERT']
self.secure_key = self.config_parameters['SECURE_KEY']
self.root_cert = self.config_parameters['ROOT_CERT']
self.machine_config = self.config_parameters['MACHINE_CONFIG_PATH']
with open(self.machine_config) as json_file:
data = json.load(json_file)
self.serial_num = data['serial_num']
self.model_type = data['model_type']
self.unique_id = self.serial_num
# ------------------------------------------------------------------------------
# -- PROVISIONING HOOKS EXAMPLE --
# Provisioning Hooks are a powerful feature for fleet provisioning. Most of the
# heavy lifting is performed within the cloud lambda. However, you can send
# device attributes to be validated by the lambda. An example is show in the line
# below (.hasValidAccount could be checked in the cloud against a database).
# Alternatively, a serial number, geo-location, or any attribute could be sent.
#
# -- Note: This attribute is passed up as part of the register_thing method and
# will be validated in your lambda's event data.
# ------------------------------------------------------------------------------
self.primary_MQTTClient = AWSIoTMQTTClient(self.unique_id)
self.test_MQTTClient = AWSIoTMQTTClient(self.unique_id)
self.primary_MQTTClient.onMessage = self.on_message_callback
self.callback_returned = False
self.message_payload = {}
self.isRotation = False