Esempio n. 1
0
def get_sensors():
    """Description goes here"""
    # Setup FogPi
    fog = Fogpi()

    lcd_queue.put("Showing humidity\nWater sensor    ", True)
    lcd_queue.join()
    # Loop to get data from the HIH-6130 sensor
    keep_looping = True
    i = 0
    while keep_looping:
        i += 1
        #
        if i % 20 == 0:
            water = fog.get_H2O()
            sta, hum, tempout = hih613.hih6130()
            # Put the sensor data into a dictionary
            dict = {"field1": hum, "field2": tempout, "field3": water}
            output = "H:{}% T:{}{}C\nH2O: {}          ".format(dict["field1"], dict["field2"], chr(223), dict["field3"])
            lcd_queue.put(output, True)
            lcd_queue.join()
            i = 0

        # Every 100 milliseconds, read the switches
        press = read_buttons()

        # Take action on switch press
        # SELECT button = exit
        if press == SELECT:
            keep_looping = False
            lcd_queue.put("Press SELECT to \n   view menu    ", True)
            lcd_queue.join()
        delay_milliseconds(99)
Esempio n. 2
0
def housekeeper():
    try:  # try to take a picture with the camera
        camera.capture("/var/www/image.jpg")
    except:
        err = 1 + 1  # doesn't do anything, just needed some code inside except block

    global solenoidstate
    global lastopened
    global lastclosed
    global collectorstate
    logger = logging.getLogger(__name__)
    sta, hum, tempout = hih613.hih6130()
    fog = Fogpi()
    data_to_mySQL(hum=hum, tempout=tempout, water=rainsensor.rain, status=False)

    if (
        rainsensor.isRaining and hum >= 85 and solenoidstate == 0
    ):  # if rain detected in polling period and humidity above 75%, try and turn on collector
        logger.info(
            "Humidity and rain threshold for big fan has been reached! Big fan firing (Hum= "
            + str(hum)
            + " rain frequency= "
            + str(rainsensor.rain)
            + ")"
        )
        lastopened = datetime.now().replace(microsecond=0)
        collectorstate = True
        fog.solenoid1()
        fog.solenoid2()
        solenoidstate = 1
        time.sleep(1)
        door1, door2 = fog.get_doors()
        if (door1 == 0) or (door2 == 0):  # if either door still closed, try and open them again
            logger.info("One of the doors is still closed: Door1: " + str(door1) + " Door2: " + str(door2))
            fog.solenoid1()
            fog.solenoid2()
            time.sleep(1)
        door1, door2 = fog.get_doors()
        if door1 and door2:  # if both doors open, start fan
            logger.info("Both doors are open and big fan is on")
            fog.big_fan_on()
    elif hum < 85:  # if humidity is less than 75
        if collectorstate == True:  # if collector on turn off
            print ("humidity has dropped below threshold, turning off")
            collectorstate = False
            lastclosed = datetime.now().replace(microsecond=0)  # set time that collector was last deactivated
        fog.big_fan_off()
        solenoidstate = 0

    print (
        "Temp: "
        + str(tempout)
        + " Humidity: "
        + str(hum)
        + " Rain Count now: "
        + str(rainsensor.rain)
        + " this hour: "
        + str(rainsensor.hourrain)
    )
    # calls function which writes index.html to var/www when given the displayed variables
    generate_page(
        str(datetime.now().replace(microsecond=0)),
        str(hum),
        str(tempout),
        str(rainsensor.hourrain),
        str(lastopened),
        str(lastclosed),
        collectorstate,
        str(rainsensor.rain),
    )

    threading.Timer(5, housekeeper).start()  # recalls housekeeping in 5 seconds
Esempio n. 3
0
def get_fog():
    """Description goes here"""
    logger = logging.getLogger(__name__)

    # Setup FogPi
    fog = Fogpi()
    housekeeper()
    # humidity cutoff for turing big fan on
    cutoff_bigfan = 75

    # solenoid state will increment to 1 if there is water
    solenoid_state = 0

    lcd_queue.put("Starting fog    \ncollector...   ", True)
    lcd_queue.join()

    # Loop to get data from the HIH-6130 sensor
    keep_looping = True
    # keep looping counter, first pass of loop will take a reading
    i = 19

    # Fog detection logic
    found_fog = "N"
    previous = "N"

    # LCD message logic
    exit_message = False
    little_fan_on = False
    exit_message_counter = 0
    exit_message_limit = 3  # 20 * .100 = 2 seconds, 3 loops = 6 seconds till timeout

    water_detected = False

    # mySQL control logic, first pass of loop will take record to the database
    j = 599

    while keep_looping:
        i += 1
        j += 1
        # 2 second delay (or 200 msec)
        if i % 20 == 0:

            # Get value from the water sensor
            water = fog.get_H2O()

            # If there's water there must be fog!

            sta, hum, tempout = hih613.hih6130()

            # send the data to the mySQL database called collectfog
            # the table is called sensors
            if j % 600 == 0:
                # puts data into the mySQL database... use phpmyadmin to get the data
                # Set status to True if you want to see the sensor data printed out to the screen
                # data_to_mySQL(hum=hum, tempout=tempout, water=water, status=False)
                j = 0

            """
            First checks if exit message is on, if it is
            ensures that timeout hasn't happened yet.
            If it has, unflag exit_message
            """
            if exit_message:
                exit_message_counter += 1
                if exit_message_counter > exit_message_limit:
                    exit_message = False
                    exit_message_counter = 0

            """
            If exit message is not printed, update output.  Otherwise, ignore.
            """
            if not exit_message:
                # Put the sensor data into a dictionary
                dict = {"field1": hum, "field2": tempout, "field3": water}
                output = "H:%s%% T: %s%sC\nH2O: %s Fog: %s(%s)" % (
                    dict["field1"],
                    dict["field2"],
                    chr(223),
                    dict["field3"],
                    found_fog,
                    previous,
                )
                lcd_queue.put(output, True)
                lcd_queue.join()

        # Every 100 milliseconds, read the switches
        press = read_buttons()

        # Take action on switch press
        # SELECT button = exit
        if press == SELECT:
            exit_message = True
            lcd_queue.put("Press RIGHT to  \n stop collector ", True)
            lcd_queue.join()
        if (press == RIGHT) and (exit_message):
            lcd_queue.put("Press SELECT to \n   view menu    ", True)
            lcd_queue.join()
            # reset the GPIO's
            GPIO.cleanup()
            # end the loop and exit out to main menu
            keep_looping = False
            exit_message = False
            little_fan_on = False

        delay_milliseconds(99)