def __init__(self): config = cmConfig() self.logger = logging.getLogger(__name__) formatter = logging.Formatter( '%(asctime)s - %(module)s - %(funcName)s - %(levelname)s - %(message)s' ) # setup debug level if config.option_list['DEFAULT']['DEBUG_LOG_LEVEL'] == 'DEBUG': self.logger.setLevel(logging.DEBUG) elif config.option_list['DEFAULT']['DEBUG_LOG_LEVEL'] == 'INFO': self.logger.setLevel(logging.INFO) elif config.option_list['DEFAULT']['DEBUG_LOG_LEVEL'] == 'ERROR': self.logger.setLevel(logging.ERROR) else: self.logger.setLevel(logging.DEBUG) # set File Handler DEBUG logger_file = config.option_list['DEFAULT'][ 'DATA_FILE_PATH'] + self.LOGGER_DEBUG_FILE self.fh = logging.FileHandler(logger_file) self.fh.setLevel(logging.DEBUG) self.fh.setFormatter(formatter) self.logger.addHandler(self.fh) # set Stream Handler ERROR self.sh = logging.StreamHandler() self.sh.setLevel(logging.ERROR) self.sh.setFormatter(formatter) self.logger.addHandler(self.sh)
def __init__(self, logger): self.logger = logger self.config = cmConfig() # Set next tweet time. self.next_datetime = datetime.datetime.today() - datetime.timedelta( minutes=20) # Tweet a message quickly, if watering. self.state_watering = False # set twitter.com OAuth key self.access_token = self.config.option_list['Twitter'][ 'TWITTER_ACCESS_TOKEN'] self.access_secret = self.config.option_list['Twitter'][ 'TWITTER_ACCESS_SECRET'] self.consumer_key = self.config.option_list['Twitter'][ 'TWITTER_CONSUMER_KEY'] self.consumer_secret = self.config.option_list['Twitter'][ 'TWITTER_CONSUMER_SECRET'] # Ignore time condition, if clock_check is flase. if self.config.option_list['Twitter']['MESSAGE_CLOCK_CHECK'] == 'True': self.clock_check = True else: self.clock_check = False
def __init__(self, logger): self.logger = logger self.config = cmConfig() self.soil_moisture_dry = int(self.config.option_list['Message'] ['MESSAGE_CONDITION_SOIL_MOISTURE_DRY']) self.soil_moisture_a_little_dry = int( self.config.option_list['Message'] ['MESSAGE_CONDITION_SOIL_MOISTURE_A_LITLE_DRY'])
def receivePacket(self, eo_queue): """Receive packet data via serial port. シリアルポートからパケットを受信します。 Receive packet data via serial port. """ # open serial port config = cmConfig() serialport = config.option_list['DEFAULT']['SERIAL_PORT'] eo_serial = serial.Serial(serialport, 57600, timeout=0.01, bytesize=8, parity='N', stopbits=1) if eo_serial.isOpen(): self.logger.info("close serial port:{0}".format(serialport)) eo_serial.close() self.logger.info("open serial port:{0}".format(serialport)) eo_serial.open() if eo_serial.isOpen(): self.logger.info("opened serial port:{0}".format(serialport)) # read packet p_dat = b'' p_dat_pre = b'' p_list = [] p_list_offset = 0 p_list_length = 0 eo_parser = EnOceanTelegramParser(self.logger) while True: # read packet 1 byte p_dat = binascii.hexlify(eo_serial.read(1)) if p_dat == b'': continue # read sync packet b'55' if p_list_offset == 0: if p_dat == eo_parser.ESP3_HEADER_SYNC_BYTE: p_list.append(p_dat) p_list_offset += 1 # read data length elif p_list_offset == 1: p_list.append(p_dat) p_list_offset += 1 p_dat_pre = p_dat elif p_list_offset == 2: p_list.append(p_dat) p_list_offset += 1 p_list_length = struct.unpack( '>H', binascii.unhexlify(p_dat_pre + p_dat))[0] # read option length elif p_list_offset == 3: p_list.append(p_dat) p_list_offset += 1 p_list_length += struct.unpack('>B', binascii.unhexlify( p_dat))[0] + eo_parser.ESP3_HEADER_SIZE + 1 self.logger.debug( "receive packet length:{0}".format(p_list_length)) # check max packet length if p_list_length > eo_parser.ESP3_MAX_PACKET_SIZE: self.logger.error( "receive packet exceeded max packet length:{0}".format( p_list_length)) p_dat_pre = b'' p_list = [] p_list_offset = 0 p_list_length = 0 # read packet data elif p_list_offset < (p_list_length - 1): p_list.append(p_dat) p_list_offset += 1 # set packet data to the thread queue elif p_list_offset >= (p_list_length - 1): p_list.append(p_dat) eo_queue.put(p_list) self.logger.info("receive packet data:{0}".format(p_list)) p_dat_pre = b'' p_list = [] p_list_offset = 0 p_list_length = 0 # sleep 0.1 msec time.sleep(0.0001)
def __init__(self, logger): self.logger = logger self.config = cmConfig()
def __init__(self, logger): self.logger = logger config = cmConfig() self.db_file = config.option_list['DEFAULT'][ 'DATA_FILE_PATH'] + self.DATA_STORE_FILE