def reg_msg_handler(self, msg_info, reply=None):
     try:
         logger.debug("Registration msg handler called.")
         if reply:
             for single_response in reply.payloads:
                 if single_response.return_value == 0:
                     logger.info("\t\tRegistration ACK received.")
                     # change status to YES in config file
                     config = ConfigObj(config_file_name)
                     config["Registered"] = "YES"
                     config["UTC Time"] = single_response.output
                     bashit("date -s@"+str(single_response.output))
                     config.write()
                     start_communication_with_nc_event.set()
                     logger.info("Start_communication_with_nc_event is set.")
                 else:
                     logger.critical("ERROR: Unknown ACK received: Discarding..")
             return   
         # handle failure
         logger.critical("Registration timeout.............")
         msg_info[2] = self.calculate_expiration_time(registration_type, None)
         self.add_to_sent_msgs_bfr(msg_info)
         self.send_msg_to_nc(msg_info[3])
         logger.critical("Registration msg resent.............")
     except Exception as inst:
         logger.critical("ERROR: Exception in reg_msg_handler: " + str(inst))
 def data_msg_handler(self, msg_info, reply=None):
     try:
         logger.debug("Data msg handler called.")
         if reply:
             for single_response in reply.payloads:
                 if single_response.output == acknowledgment and not single_response.return_value:
                     logger.info("\t\tData ACK received.")
                 else:
                     logger.critical("Unknown ACK received: Discarding..")
             return
         # handle failure
         logger.critical("Data Packet timeout.............")
         msg_info[2] = self.calculate_expiration_time(data_type, None)
         self.add_to_sent_msgs_bfr(msg_info)
         self.send_msg_to_nc(msg_info[3])
         logger.critical("Data msg resent.............")
     except Exception as inst:
         logger.critical("ERROR: Exception in data_msg_handler: " + str(inst))
 def run(self):
     try:
         nc_ip = self.get_nc_ip()
         logger.debug("Starting " + self.thread_name + "\n\n")
         self.shutdown = 0
         self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         self.connect( (nc_ip, self.nc_port) )                                                             
         logger.info("CONNECTED............."+"\n\n")
         while True:
             # Starts the loop which polls the open socket for *count* times,
             # comes out of the asyncore loop and then repeats after 0.01s
             # Performance widely varies based on sleep time and count's value
             # When count=0/None control will never come out of the asyncore loop
             asyncore.loop(timeout=0.01, use_poll=True, map=None)  # , count=n) can be added. n>=1                                                                   
             time.sleep(0.01)
     except Exception as inst:
         logger.critical("Exception in run: " + str(inst) + "\n\n")
         self.shutdown = 1
         self.handle_close()
         logger.critical("Error in connecting with the NC.\n\n") 
         time.sleep(10)
         self.run()
 def close(self):
     for thread in sensor_thread_list:
         thread.join(1)
     logger.info("All per sensor threads exited."+ "\n\n")