43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from flask import Flask, redirect, url_for, request, render_template
|
|
import RPi.GPIO as GPIO
|
|
import sys
|
|
import time
|
|
|
|
app = Flask(__name__)
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
GPIO.setwarnings(False)
|
|
|
|
RELAIS_1_GPIO = 0
|
|
RELAIS_2_GPIO = 1
|
|
|
|
GPIO.setup(RELAIS_1_GPIO, GPIO.OUT)
|
|
GPIO.setup(RELAIS_2_GPIO, GPIO.OUT)
|
|
|
|
GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)
|
|
GPIO.output(RELAIS_2_GPIO, GPIO.HIGH)
|
|
|
|
@app.route('/')
|
|
def start():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/index',methods = ['POST', 'GET'])
|
|
def index():
|
|
if request.method == 'POST':
|
|
if request.form['ant_button'] == 'up':
|
|
GPIO.output(RELAIS_2_GPIO, GPIO.LOW)
|
|
time.sleep(.100)
|
|
GPIO.output(RELAIS_2_GPIO, GPIO.HIGH)
|
|
return redirect(url_for('start'))
|
|
if request.form['ant_button'] == 'down':
|
|
GPIO.output(RELAIS_1_GPIO, GPIO.LOW)
|
|
time.sleep(.100)
|
|
GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)
|
|
return redirect(url_for('start'))
|
|
else:
|
|
print(request.form.action)
|
|
return redirect(url_for('start'))
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port='5000')
|