Example #1
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']
	
		# Sample Provisioning Template requests a serial number as a 
		# seed to generate Thing names in IoTCore. Simulating here.
		self.unique_id = "1234567-abcde-fghij-klmno-1234567abc-TLS350" 
		self.unique_id = str(int(round(time.time() * 1000)))

		# ------------------------------------------------------------------------------
		#  -- 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
Example #2
0
    cur = cnxn.cursor()
    result = cur.execute("Select * from Things")
    rows = result.fetchall()
    data = []
    for row in rows:
        data.append(list(row))
    
    return jsonify({'result':data}), status.HTTP_200_OK

######### Provisioning certificate #####################

#Set Config path
CONFIG_PATH = 'config.ini'

config = Config(CONFIG_PATH)
config_parameters = config.get_section('SETTINGS')
secure_cert_path = config_parameters['SECURE_CERT_PATH']
bootstrap_cert = config_parameters['CLAIM_CERT']


def callback(payload):
    print(payload)

card = ""
@app.route('/provisioning-cert',methods=['POST'])
def run_provisioning(isRotation=False):
    
    provisioner = ProvisioningHandler(CONFIG_PATH)

    if isRotation:
        provisioner.get_official_certs(callback, isRotation=True)