Exemple #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)
Exemple #2
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)