Пример #1
0
def door_close():
    try:
        door_funcs.setup(open_door_pin, close_door_pin)
        door_funcs.activate_door('close', 26, open_door_pin, close_door_pin)
    except:
        return render_template("index.html")
    return render_template("hen_door.html")
Пример #2
0
def custom_door():
    time = float(request.form['time'])
    direction = request.form['direction']
    try:
        door_funcs.setup(open_door_pin, close_door_pin)
        door_funcs.activate_door(direction, time, open_door_pin,
                                 close_door_pin)
    except:
        return render_template("index.html")
    return render_template("hen_door.html")
Пример #3
0
from collections import Counter
from twilio.rest import Client
sys.path.insert(0, '../src/')
#sys.path.append(os.path.join(os.path.dirname(sys.path[0]), '../src/'))
import funcs as myfuncs
import hen_door as door_funcs

# setup pins
open_door_pin = 17
close_door_pin = 18

open_door_pin = 26
close_door_pin = 20

# setup hen door - these are pins
door_funcs.setup(open_door_pin, close_door_pin)

# for log..
print('-------------------------------------------------------------')
print('----------------- new app instance --------------------------')
print('-------------------------------------------------------------')
print(f'app start time: {datetime.now()}')

# setup twilio stuff
# these are stored in /etc/rc.local
account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
auth_token = os.environ.get('TWILIO_AUTH_TOKEN')
twilio_phone = os.environ.get('TWILIO_PHONE_NUM')
my_phone = os.environ.get('MY_PHONE_NUM')
# mer_phone = os.environ['MER_PHONE_NUM']
Пример #4
0
def main(open_time, close_time):
    '''
    function to control hen door
    params are open and close times in datetime format
    runs forever (while loop)
    '''

    logging.info('starting hen door func...')
    # setup current_time
    current_time = datetime.datetime.now().replace(microsecond=0).time()
    logging.info(f'setting hen door func current time as {current_time}')

    # setup current status of door..
    # TODO: how do we determine this??
    # this only gets complicated if we start pi and door is closed
    # when it should be open..
    # assume it is in correct position..
    # TODO: maybe we can track the time in each direction to correct if needed
    # and also to define time limits in both direction just in case..
    if current_time >= open_time and current_time <= close_time:
        door_open = True
        logging.info(
            f'setting door as open because: current time is {current_time}'
            f' and open time is {open_time} and close time is {close_time}')
    else:
        door_open = False
        logging.info(
            f'setting door as closed because: current time is {current_time}'
            f' and open time is {open_time} and close time is {close_time}')

    # setup while forever to keep checking time..
    while True:
        # logging.info('starting or continuing hen door while loop to check time...')
        # check time
        current_time = datetime.datetime.now().replace(microsecond=0).time()
        # logging.info(f'current time is: {current_time}')

        # if time is in range..
        if current_time >= open_time and current_time <= close_time and door_open == False:
            # then open door..
            try:
                door_funcs.setup(open_door_pin, close_door_pin)
                door_funcs.activate_door('close', 26, open_door_pin,
                                         close_door_pin)
                logging.info(
                    f'opening door.. because current time is {current_time}')
                door_open = True
            except:
                return None
        elif current_time >= close_time and door_open == True:
            # then close door..
            try:
                door_funcs.setup(open_door_pin, close_door_pin)
                door_funcs.activate_door('open', 25, open_door_pin,
                                         close_door_pin)
                logging.info(
                    f'closing door..because current time is {current_time}')
                door_open = False
            except:
                return None
        else:
            # logging.info(f'waiting because open or close conditions not met and current time is {current_time}')
            pass

        # then wait 2.5 mins before checking again
        # logging.info(f'waiting for 2.5 mins because current time is {current_time}')
        time.sleep(150)
        current_time = datetime.datetime.now().replace(microsecond=0).time()