def provisioning_client_sample_run(): global GLOBAL_PROV_URI global ID_SCOPE global SECURITY_DEVICE_TYPE global PROTOCOL try: provisioning_client = ProvisioningDeviceClient(GLOBAL_PROV_URI, ID_SCOPE, SECURITY_DEVICE_TYPE, PROTOCOL) version_str = provisioning_client.get_version_string() print ( "\nProvisioning API Version: %s\n" % version_str ) provisioning_client.set_option("logtrace", True) provisioning_client.register_device(register_device_callback, None, register_status_callback, None) try: # Try Python 2.xx first raw_input("Press Enter to interrupt...\n") except: pass # Use Python 3.xx in the case of exception input("Press Enter to interrupt...\n") except ProvisioningError as provisioning_error: print ( "Unexpected error %s" % provisioning_error ) return except KeyboardInterrupt: print ( "Provisioning Device Client sample stopped" )
class ProvisioningManager(object): def __init__(self, global_prov_uri, id_scope, security_device_type=ProvisioningSecurityDeviceType.X509, protocol=ProvisioningTransportProvider.HTTP): self.client_protocol = protocol self.client = ProvisioningDeviceClient(global_prov_uri, id_scope, security_device_type, protocol) self.version_str = self.client.get_version_string() def set_option(self, option_name, option_value): try: self.client.set_option(option_name, option_value) except ProvisioningError as provisioning_error: print("set_option failed (%s)" % provisioning_error) def register_device(self, register_device_callback, user_context, register_status_callback, user_status_context): try: self.client.register_device(register_device_callback, user_context, register_status_callback, user_status_context) except ProvisioningError as provisioning_error: print("register_device failed (%s)" % provisioning_error)
def run_e2e_provisioning(): global GLOBAL_PROV_URI global ID_SCOPE global DEVICE_CALLBACK_EVENT global DEVICE_CALLBACK_TIMEOUT global REGISTRATION_OK SECURITY_DEVICE_TYPE = ProvisioningSecurityDeviceType.X509 PROTOCOL = ProvisioningTransportProvider.HTTP try: # prepare provisioning_client = ProvisioningDeviceClient(GLOBAL_PROV_URI, ID_SCOPE, SECURITY_DEVICE_TYPE, PROTOCOL) version_str = provisioning_client.get_version_string() print("\nProvisioning API Version: %s\n" % version_str) provisioning_client.set_option("logtrace", True) # act DEVICE_CALLBACK_EVENT.clear() provisioning_client.register_device(register_device_callback, None, register_status_callback, None) DEVICE_CALLBACK_EVENT.wait(DEVICE_CALLBACK_TIMEOUT) # verify assert STATUS_CALLBACKS > 0, "Error: status_callback callback has not been called" assert DEVICE_CALLBACKS > 0, "Error: device_callback callback has not been called" assert REGISTRATION_OK, "Error: Device registration failed" ########################################################################### retval = 0 except Exception as e: print("") print("run_e2e_provisioning() failed with exception: {0}".format(e)) retval = 1 return retval
def run_e2e_provisioning(): global GLOBAL_PROV_URI global ID_SCOPE global DEVICE_CALLBACK_EVENT global DEVICE_CALLBACK_TIMEOUT global REGISTRATION_OK SECURITY_DEVICE_TYPE = ProvisioningSecurityDeviceType.X509 PROTOCOL = ProvisioningTransportProvider.HTTP try: # prepare provisioning_client = ProvisioningDeviceClient(GLOBAL_PROV_URI, ID_SCOPE, SECURITY_DEVICE_TYPE, PROTOCOL) version_str = provisioning_client.get_version_string() print ( "\nProvisioning API Version: %s\n" % version_str ) provisioning_client.set_option("logtrace", True) # act DEVICE_CALLBACK_EVENT.clear() provisioning_client.register_device(register_device_callback, None, register_status_callback, None) DEVICE_CALLBACK_EVENT.wait(DEVICE_CALLBACK_TIMEOUT) # verify assert STATUS_CALLBACKS > 0, "Error: status_callback callback has not been called" assert DEVICE_CALLBACKS > 0, "Error: device_callback callback has not been called" assert REGISTRATION_OK, "Error: Device registration failed" ########################################################################### retval = 0 except Exception as e: print ( "" ) print ("run_e2e_provisioning() failed with exception: {0}".format(e)) retval = 1 return retval
def provision_device(): global GLOBAL_PROV_URI global ID_SCOPE global SECURITY_DEVICE_TYPE global PROTOCOL global kill_received log = logger.getLogger() try: provisioning_client = ProvisioningDeviceClient(GLOBAL_PROV_URI, ID_SCOPE, SECURITY_DEVICE_TYPE, PROTOCOL) version_str = provisioning_client.get_version_string() log.debug( "\nProvisioning API Version: %s\n" % version_str ) provisioning_client.set_option("logtrace", False) provisioning_client.register_device(register_device_callback, None, register_status_callback, None) # try: # # Try Python 2.xx first # raw_input("Press Enter to interrupt...\n") # except: # pass # # Use Python 3.xx in the case of exception # input("Press Enter to interrupt...\n") # log.debug("sleeping for DPS") # import time; time.sleep(10) # log.debug("done sleeping for DPS") while not kill_received: time.sleep(1) except ProvisioningError as provisioning_error: log.error( "Unexpected error %s" % provisioning_error ) return except KeyboardInterrupt: log.error( "Provisioning Device Client sample stopped" )
class ProvisioningManager(object): def __init__( self, global_prov_uri, id_scope, security_device_type=ProvisioningSecurityDeviceType.X509, protocol=ProvisioningTransportProvider.HTTP): self.client_protocol = protocol self.client = ProvisioningDeviceClient(global_prov_uri, id_scope, security_device_type, protocol) self.version_str = self.client.get_version_string() def set_option(self, option_name, option_value): try: self.client.set_option(option_name, option_value) except ProvisioningError as provisioning_error: print ( "set_option failed (%s)" % provisioning_error ) def register_device(self, register_device_callback, user_context, register_status_callback, user_status_context): try: self.client.register_device(register_device_callback, user_context, register_status_callback, user_status_context) except ProvisioningError as provisioning_error: print ( "register_device failed (%s)" % provisioning_error )