Пример #1
0
    def handle_noargs(self, **options):

        th = TerrariumHelper()
        terrarium = th.get_terrarium()

        if terrarium is not None:

            if terrarium.is_sleeping() is False:

                fan = th.get_fan(terrarium)

                if fan is not None:
                    fan.on()
                    sleep(5 * 60)
                    fan.off()
Пример #2
0
    def handle_noargs(self, **options):

        th = TerrariumHelper()
        terrarium = th.get_terrarium()

        if terrarium is not None:

            if terrarium.is_sleeping() is False:

                fan = th.get_fan(terrarium)

                if fan is not None:
                    fan.on()
                    sleep(5*60)
                    fan.off()
Пример #3
0
    def handle_noargs(self, **options):

        config = Config.objects.first()
        terrarium = config.terrarium
        th = TerrariumHelper()

        if terrarium is not None:
            if terrarium.is_sleeping() is False:

                fogger = th.get_fogger(terrarium)

                if fogger is not None:
                    fogger.on()
                    sleep(20)
                    #sleep(3*60)
                    fogger.off()
Пример #4
0
def main():

    control = KarniPiControl()

    # run as far as you can
    while True:
        exit_code = control.get_exit_code()
        KarniLogger().log_info("Checking for exit code..." + str(exit_code))

        if int(exit_code) == 0:
            KarniLogger().log_info("Staring next cycle...")

            try:
                try:
                    terrarium = TerrariumHelper().get_terrarium()
                except:
                    KarniLogger().log_info("Couldn't get terrarium...")

                if terrarium.sleep_mode is False:
                    control.handle_control(terrarium)
                else:
                    KarniLogger().log_info("Sleeping so well...")

            except (KeyboardInterrupt, SystemExit):
                KarniLogger().log_info("Exiting...")
                sys.exit()
            finally:
                KarniLogger().log_info("Idling for 10 minutes")
                time.sleep(10 * 60)
        else:
            KarniLogger().log_info("Exiting due to exit code...")
            sys.exit()
Пример #5
0
def index(request):

    mh = MainHelper()

    latest_terrarium_data = TerrariumHelper().GetCurrentTerrariumData()
    today = datetime.today()
    latest_log_data = mh.get_karnipi_log().filter(datetime__year=today.year,
                                                  datetime__month=today.month,
                                                  datetime__day=today.day).order_by('-datetime')

    picture = None

    if Picture.objects.count() > 0:
        picture = Picture.objects.latest('taken_on')

    status_overview = mh.get_status_overview()

    template = loader.get_template('main/index.html')
    context = RequestContext(request, {
        'latest_terrarium_data': latest_terrarium_data,
		'latest_picture': picture,
        'latest_log_data': latest_log_data,
        'status_overview': status_overview,
        'current_site': 'overview',
    })
    return HttpResponse(template.render(context))
Пример #6
0
    def get_status_overview():

        th = TerrariumHelper()
        terrarium = th.get_terrarium()
        heater = th.get_heater(terrarium)
        light = th.get_light(terrarium)
        fogger = th.get_fogger(terrarium)
        sprinkler = th.get_sprinkler(terrarium)
        fan = th.get_fan(terrarium)

        status = []

        for i in I2CActor.objects.all():
            status.append(i)

        return status
Пример #7
0
    def handle_control(self, terrarium):

        if self.action is None:
            self.action = "heating"

        KarniLogger().log_info("Getting terrarium data...")
        sht21 = TerrariumHelper().get_sht21_sensor(terrarium)
        print sht21
        temperature = int(sht21.read_temperature())
        print temperature
        # terra_data = TerrariumHelper().GetCurrentTerrariumData()

        KarniLogger().log_info("Accessing heater...")
        heater = TerrariumHelper().get_heater(terrarium)

        # if heater is available
        if heater is not None:
            KarniLogger().log_info("Terrarium: {0} C".format(int(temperature)))
            KarniLogger().log_info("Ziel-Temperatur: {0} C".format(int(terrarium.temperature_max)))
            KarniLogger().log_info("Action is '{0}'".format(self.action))

            if int(temperature) < int(terrarium.temperature_min):
                self.action = "heating"
                heater.on()
                KarniLogger().log_info("Heating...")
            elif (int(temperature) <= int(terrarium.temperature_max)) & (self.action == "heating"):
                heater.on()
            elif (int(temperature) <= int(terrarium.temperature_max)) & (self.action == "cool down"):
                heater.off()
            elif int(temperature) > int(terrarium.temperature_max):
                self.action = "cool down"
                heater.off()
                KarniLogger().log_info("Cooling down...")
            else:
                KarniLogger().log_info("Don't know what to do...")
Пример #8
0
    def handle_control(self, terrarium):

        if self.action is None:
            self.action = "heating"

        KarniLogger().log_info("Getting terrarium data...")
        sht21 = TerrariumHelper().get_sht21_sensor(terrarium)
        print sht21
        temperature = int(sht21.read_temperature())
        print temperature
        # terra_data = TerrariumHelper().GetCurrentTerrariumData()

        KarniLogger().log_info("Accessing heater...")
        heater = TerrariumHelper().get_heater(terrarium)

        # if heater is available
        if heater is not None:
            KarniLogger().log_info("Terrarium: {0} C".format(int(temperature)))
            KarniLogger().log_info("Ziel-Temperatur: {0} C".format(
                int(terrarium.temperature_max)))
            KarniLogger().log_info("Action is '{0}'".format(self.action))

            if int(temperature) < int(terrarium.temperature_min):
                self.action = "heating"
                heater.on()
                KarniLogger().log_info("Heating...")
            elif (int(temperature) <= int(
                    terrarium.temperature_max)) & (self.action == "heating"):
                heater.on()
            elif (int(temperature) <= int(
                    terrarium.temperature_max)) & (self.action == "cool down"):
                heater.off()
            elif int(temperature) > int(terrarium.temperature_max):
                self.action = "cool down"
                heater.off()
                KarniLogger().log_info("Cooling down...")
            else:
                KarniLogger().log_info("Don't know what to do...")
Пример #9
0
    def handle_noargs(self, **options):

        th = TerrariumHelper()
        th.WriteCurrentTerraDataToLog()