def __init__(self, username, password, con): log.info("Logging into DCC") self.comms = con self.con = con.wss self.username = username self.password = password self.proto = HelixProtocol(self.con, username, password) self._iotcc_json = self._create_iotcc_json() self.dev_file_path = self._get_file_storage_path("dev_file_path") # Liota internal entity file system path special for iotcc self.entity_file_path = self._get_file_storage_path("entity_file_path") self.file_ops_lock = Lock() def on_receive_safe(msg): try: log.debug("Received msg: {0}".format(msg)) json_msg = json.loads(msg) self.proto.on_receive(json.loads(msg)) log.debug("Processed msg: {0}".format(json_msg["type"])) if json_msg["type"] == "connection_verified": log.info("Connection verified") exit() except Exception: raise log.exception( "Error received on connecting to DCC instance. Please verify the credentials and try again." ) thread = threading.Thread(target=self.con.run) self.con.on_receive = on_receive_safe thread.daemon = True thread.start() thread.join() log.info("Logged in to DCC successfully")
def __init__(self, username, password, con): log.info("Logging into DCC") self.comms = con self.con = con.wss self.username = username self.password = password self.proto = HelixProtocol(self.con, username, password) self.info_file = self._init_info() def on_receive_safe(msg): try: log.debug("Received msg: {0}".format(msg)) json_msg = json.loads(msg) self.proto.on_receive(json.loads(msg)) log.debug("Processed msg: {0}".format(json_msg["type"])) if json_msg["type"] == "connection_verified": log.info("Connection verified") exit() except Exception: raise log.exception( "Error received on connecting to DCC instance. Please verify the credentials and try again.") thread = threading.Thread(target=self.con.run) self.con.on_receive = on_receive_safe thread.daemon = True thread.start() thread.join() log.info("Logged in to DCC successfully")
def __init__(self, con): log.info("Logging into DCC") self.comms = con if not self.comms.identity.username: log.error("Username not found") raise ValueError("Username not found") elif not self.comms.identity.password: log.error("Password not found") raise ValueError("Password not found") thread = threading.Thread(target=self.comms.receive) thread.daemon = True # This thread will continuously run in background to receive response or actions from DCC thread.start() # Wait for Subscription to be complete and then proceed to publish message time.sleep(0.5) self.proto = HelixProtocol(self.comms, self.comms.identity.username, self.comms.identity.password) self._iotcc_json = self._create_iotcc_json() self.counter = 0 self.recv_msg_queue = self.comms.userdata self.dev_file_path = self._get_file_storage_path("dev_file_path") # Liota internal entity file system path special for iotcc self.entity_file_path = self._get_file_storage_path("entity_file_path") self.file_ops_lock = Lock() try: def on_response(msg): log.debug("Received msg: {0}".format(msg)) json_msg = json.loads(msg) self.proto.on_receive(json_msg) if json_msg["type"] == "connection_response": if json_msg["body"]["result"] == "succeeded": log.info("Connection verified") else: raise Exception("Helix Protocol Version mismatch") else: log.debug("Processed msg: {0}".format(json_msg["type"])) on_response(self.recv_msg_queue.get(True, 300)) # Block on Queue for not more then 300 seconds else it will raise an exception on_response(self.recv_msg_queue.get(True, 300)) except Exception as error: self.comms.client.disconnect() log.error("HelixProtocolException: " + repr(error)) raise Exception("HelixProtocolException")
def __init__(self, username, password, con): log.info("Logging into DCC") self.comms = con self.username = username self.password = password self.proto = HelixProtocol(self.comms, username, password) self._iotcc_json = self._create_iotcc_json() self.counter = 0 self.recv_msg_queue = self.comms.userdata self.dev_file_path = self._get_file_storage_path("dev_file_path") # Liota internal entity file system path special for iotcc self.entity_file_path = self._get_file_storage_path("entity_file_path") self.file_ops_lock = Lock() def on_response(msg): try: log.debug("Received msg: {0}".format(msg)) json_msg = json.loads(msg) self.proto.on_receive(json_msg) if json_msg["type"] == "connection_response" and json_msg[ "body"]["result"] == "succeeded": log.info("Connection verified") return True else: log.debug("Processed msg: {0}".format(json_msg["type"])) on_response(self.recv_msg_queue.get(True, 10)) except Exception as error: log.error("HelixProtocolException: " + repr(error)) thread = threading.Thread(target=self.comms.receive) thread.daemon = True # This thread will continuously run in background to receive response or actions from DCC thread.start() # Block on Queue for not more then 10 seconds else it will raise an exception on_response(self.recv_msg_queue.get(True, 10)) log.info("Logged in to DCC successfully")