AntennaPi/antennapi.py

72 lines
1.7 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
enabled = '#bbffbb'
disabled = '#eeeeee'
def b1():
coax1 = GPIO.input(RELAIS_1_GPIO)
coax2 = GPIO.input(RELAIS_2_GPIO)
if coax1 == 0 and coax2 == 1:
return enabled
else:
return disabled
def b2():
coax1 = GPIO.input(RELAIS_1_GPIO)
coax2 = GPIO.input(RELAIS_2_GPIO)
if coax1 == 1 and coax2 == 0:
return enabled
else:
return disabled
def b3():
coax1 = GPIO.input(RELAIS_1_GPIO)
coax2 = GPIO.input(RELAIS_2_GPIO)
if coax1 == 1 and coax2 == 1:
return enabled
else:
return disabled
GPIO.setup(RELAIS_1_GPIO, GPIO.OUT)
GPIO.setup(RELAIS_2_GPIO, GPIO.OUT)
@app.route('/')
def start():
return render_template('index.html', bc1=b1(), bc2=b2(), bc3=b3())
@app.route('/index',methods = ['POST', 'GET'])
def index():
if request.method == 'POST':
if request.form['ant_button'] == 'ant1':
GPIO.output(RELAIS_2_GPIO, GPIO.HIGH)
GPIO.output(RELAIS_1_GPIO, GPIO.LOW)
return redirect(url_for('start'))
if request.form['ant_button'] == 'ant2':
GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)
GPIO.output(RELAIS_2_GPIO, GPIO.LOW)
return redirect(url_for('start'))
if request.form['ant_button'] == 'ant3':
GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)
GPIO.output(RELAIS_2_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')