Ejemplo n.º 1
0
def main():
    setupLogging()

    pool = Pool(processes=1)
    while (True):
        try:
            for i in range(10):
                logs = dht11_sensor.readSensor()
                if sensorReadFailure(logs):
                    time.sleep(2)
                    continue

            if not sensorReadFailure(logs):
                # store sensor logs locally
                repo.storeData(logs['temp'], logs['humid'])

                # send logs to backend server
                pool.apply_async(sendLogsToServer, [])

                # make fan activation decision
                if isDaytime(int(
                        time.strftime('%H'))) and last3LogsAreOverTempLimit(
                            repo.getLastTrio()):
                    tellstick_client.activateFan()
                else:
                    tellstick_client.deactivateFan()

            time.sleep(60)
        except:
            logging.error("%s %s", time.strftime("%d-%m-%Y %H:%M:%S"),
                          exc_info())
Ejemplo n.º 2
0
def main():
    setupLogging()

    pool = Pool(processes=1)
    while (True):
        try:
            for i in range(10):
                logs = dht11_sensor.readSensor()
                if sensorReadFailure(logs):
                    time.sleep(2)
                    continue
        
            if not sensorReadFailure(logs):
                # store sensor logs locally
                repo.storeData(logs['temp'], logs['humid'])
            
                # send logs to backend server
                pool.apply_async(sendLogsToServer, [])
                
                # make fan activation decision
                if isDaytime(int(time.strftime('%H'))) and last3LogsAreOverTempLimit(repo.getLastTrio()):
                    tellstick_client.activateFan()
                else:
                    tellstick_client.deactivateFan()
            
            time.sleep(60)
        except:
            logging.error("%s %s",time.strftime("%d-%m-%Y %H:%M:%S"),exc_info())
Ejemplo n.º 3
0
def shouldFanActivate():
    isDaytime = isCurrentHourDaytime(int(time.strftime('%H')))
    overTempLimit = last3LogsAreOverTempLimit(repo.getLastTrio())
    pingSuccess = ping_service.ping('daedalus.zyxel.com', 5)
    return overTempLimit and pingSuccess and isDaytime