def __init__(self):
        # initialize logger variable
        self.logger = logger_variable(__name__, 'CameraCapture.log')

        # initialize VideoCapture variable
        self.cap = cv2.VideoCapture(-1)
        logger.debug('VideoCapture is initialized')

        # initialize Frame height & width
        self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
        self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
        logger.debug('Frame dimension is initialized')
    def __init__(self):
        parser = ConfigParser()

        parser.read('config_files/device.conf')
        self.host = parser.get('device', 'host')
        self.port = int(parser.get('device', 'port'))
        self.clientId = parser.get('device', 'deviceId')
        self.userId = parser.get('device', 'userId')
        self.topic = parser.get('device', 'topic')
        self.rootCAPath = parser.get('device', 'rootCAPath')
        self.privateKeyPath = parser.get('device', 'privateKeyPath')
        self.certificatePath = parser.get('device', 'certificatePath')
        self.growId = parser.get('grow', 'growId')
        parser.read('config_files/plant.conf')
        self.growStartDate = None
        self.growStartDate = None
        self.myAWSIoTMQTTClient = AWSIoTMQTTClient(self.clientId)
        self.myAWSIoTMQTTClient.configureEndpoint(self.host, self.port)
        self.myAWSIoTMQTTClient.configureCredentials(self.rootCAPath,
                                                     self.privateKeyPath,
                                                     self.certificatePath)
        self.myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
        # Infinite offline Publish queueing
        self.myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)
        self.myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
        self.myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
        self.myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec
        cwd = os.getcwd()
        parent_dir = os.path.dirname(cwd)
        self.logger = logger_variable(__name__, 'log_files/AWSData.log')
        while True:

            try:
                self.logger.debug('Trying to connect to aws..')
                self.myAWSIoTMQTTClient.connect()
            except Exception as e:
                self.logger.warning('Not connected to aws..')
                self.logger.warning(e)
                print(e)
                print("Not connected...")
                print("retrying in 5 seconds....")
                time.sleep(5)
                continue
            else:
                self.logger.debug('connected to aws..')
                print("connected...")
                break
示例#3
0
    def __init__(self):
        """
        Initialize variables and operators
        1. initialize serial port
        2. initialize GPIO pins

        identifier:
            serialOpen: Serial Port
        """
        # initialize logger_variable
        self.logger = logger_variable(__name__, 'SensorData.log')

        # open serial port
        self.serialOpen = serial.Serial('/dev/ttyACM0', 115200)
        wpi.wiringPiSetupGpio()                                 # initialize wiringPi GPIO mode
        wpi.pinMode(self.interrupt_pin, 1)                      # set GPIO pins as output
        wpi.pinMode(26, 1)
            self.parser.read('config_files/plant.conf')
            self.plantCycleDuration = self.parser.get('PlantInfo',
                                                      'plantCycle')
            self.growStartDate = self.strtoDate(
                self.parser.get('PlantInfo', 'plantingDate'))
            self.estimatedHarvest = self.strtoDate(
                self.parser.get('PlantInfo', 'estimatedHarvest'))
            self.logger.debug('Config File Read')
        else:
            self.logger.error('Config File Not Found')

    def strtoDate(self, date):
        ''':type date: str
        :rtype: status: datetime.timedelta'''
        date = [int(x) for x in date.split('-')]
        formatted_date = datetime.date(date[0], date[1], date[2])
        return formatted_date


if __name__ == '__main__':
    statesv = State()
    f = open('main8.log', 'w')
    f.close()
    logger = logger_variable(__name__, 'main8.log')
    grow = GrowCycle(statesv, logger)
    grow.schedCurrentWeek('week0')
    print(grow.tempUL)
    schedule.every(grow.ledOnInterval).minutes.do(logger.info, msg='Led on')
    while True:
        schedule.run_pending()