Javascript 发送ajax请求时Flask中出现未知错误,即使来自其他函数的重复请求正常工作

Javascript 发送ajax请求时Flask中出现未知错误,即使来自其他函数的重复请求正常工作,javascript,python,ajax,flask,raspberry-pi,Javascript,Python,Ajax,Flask,Raspberry Pi,好的,我是python和flask的新手,我发现为我的RBpi运行webapp非常有用 我最初用HTML编写了应用程序,并使用javascript作为逻辑代码,但由于我现在有了一个“已完成”的应用程序(本阶段),我决定继续改进功能和能力 我更熟悉PHP,但喜欢python给我的易用性和为应用程序IE cronjobs等编写后端框架的能力 我试图通过将当前代码合并到python代码中来提供持久变量。我尝试通过使用ajax请求发送包含数据字符串的URL,然后在运行时使用该数据在我的app.py中存储

好的,我是python和flask的新手,我发现为我的RBpi运行webapp非常有用

我最初用HTML编写了应用程序,并使用javascript作为逻辑代码,但由于我现在有了一个“已完成”的应用程序(本阶段),我决定继续改进功能和能力

我更熟悉PHP,但喜欢python给我的易用性和为应用程序IE cronjobs等编写后端框架的能力

我试图通过将当前代码合并到python代码中来提供持久变量。我尝试通过使用ajax请求发送包含数据字符串的URL,然后在运行时使用该数据在我的app.py中存储一个全局变量来实现这一点

当我使用点击事件发送数据时:

<script> //set timer buttons down

function downtime1(){
     if(window.time1 !== 60)
            {
    window.time1 = window.time1 - 60;
    window.times1 = window.time1 / 60;
    $.ajax({url: '/boxtimes/1/'+window.time1,});
    document.getElementById("button1time").innerHTML = times1;
    document.getElementById("button1timeset").innerHTML = times1;
    }
}
    
function downtime2(){
         if(window.time2 !== 60)
            {
    window.time2 = window.time2 - 60;
    window.times2 = window.time2 / 60;
    $.ajax({url: '/boxtimes/2/'+window.time2,});
    document.getElementById("button2time").innerHTML = times2;
    document.getElementById("button2timeset").innerHTML = times2;
}
}
function downtime3(){
         if(window.time3 !== 60)
            {
    window.time3 = window.time3 - 60;
    window.times3 = window.time3 / 60;
    $.ajax({url: '/boxtimes/3/'+window.time3,});
    document.getElementById("button3time").innerHTML = times3;
    document.getElementById("button3timeset").innerHTML = times3;
}}
    </script>
<script> //light1 control
    window.lc1 = {{ lc1  }};
    
    if(window.lc1 == 3){ document.getElementById("llc1").style.backgroundColor = "transparent";};
    if (window.lc1 == 2){ document.getElementById("mlc1").style.backgroundColor = "transparent"; document.getElementById("llc1").style.backgroundColor = "transparent";};
    if (window.lc1 == 1){ document.getElementById("slc1").style.backgroundColor = "transparent";
                        document.getElementById("mlc1").style.backgroundColor = "transparent"; document.getElementById("llc1").style.backgroundColor = "transparent";};
    if (window.lc1 == 0){ 
    document.getElementById("slc1").style.backgroundColor = "#DB402B";
    document.getElementById("mlc1").style.backgroundColor = "#DB402B";
    document.getElementById("llc1").style.backgroundColor = "#DB402B";
        };
    

// change light setting

    
    function lightbutton1() { 
    
    if(window.lc1 == 3){ $.ajax({url: '/light/light1/3',});
         window.lc1 = 2;
    document.getElementById("llc1").style.backgroundColor = "transparent";
     }
    else if (window.lc1 == 2){ $.ajax({url: '/light/light1/2',});
        window.lc1 = 1;
    document.getElementById("mlc1").style.backgroundColor = "transparent";
        }
    else if (window.lc1 == 1){ $.ajax({url: '/light/light1/1',});
        window.lc1 = 0;
    document.getElementById("slc1").style.backgroundColor = "transparent";
        }
    else if (window.lc1 == 0){ $.ajax({url: '/light/light1/0',});
        window.lc1 = 3;
    document.getElementById("slc1").style.backgroundColor = "#DB402B";
    document.getElementById("mlc1").style.backgroundColor = "#DB402B";
    document.getElementById("llc1").style.backgroundColor = "#DB402B";
        }
    
    };
</script>
在这里下载完整的HTML代码。

下面是完整的app.py代码


'''
    Raspberry Pi GPIO Status and Control
'''
import RPi.GPIO as GPIO
from flask import Flask, render_template, request
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#define actuators GPIOs
A1 = 13
A2 = 19
A3 = 26
A4 = 13
A5 = 19
A6 = 26
A7 = 13
A8 = 19
B1 = 26
B2 = 13
B3 = 19
B4 = 26
B5 = 26
B6 = 13
B7 = 19
B8 = 26
#initialize GPIO status variables
lc1 = 3
lc2 = 3
lc3 = 3
lc4 = 3
lc5 = 3
lc6 = 3
lc7 = 3
lc8 = 3
# Define timer Variables
crnttime = 0
timerstatus = 0
# Define default button times
time1 = 1200
time2 = 1800
time3 = 2400

# Define led pins as output
GPIO.setup(A1, GPIO.OUT)   
GPIO.setup(A2, GPIO.OUT) 
GPIO.setup(A3, GPIO.OUT)
GPIO.setup(A4, GPIO.OUT)   
GPIO.setup(A5, GPIO.OUT) 
GPIO.setup(A6, GPIO.OUT)
GPIO.setup(A7, GPIO.OUT)   
GPIO.setup(A8, GPIO.OUT) 
GPIO.setup(B1, GPIO.OUT)   
GPIO.setup(B2, GPIO.OUT) 
GPIO.setup(B3, GPIO.OUT)
GPIO.setup(B4, GPIO.OUT)   
GPIO.setup(B5, GPIO.OUT) 
GPIO.setup(B6, GPIO.OUT)
GPIO.setup(B7, GPIO.OUT)   
GPIO.setup(B8, GPIO.OUT) 
# turn leds OFF 
GPIO.output(A1, GPIO.LOW)
GPIO.output(A2, GPIO.LOW)
GPIO.output(A3, GPIO.LOW)
GPIO.output(A4, GPIO.LOW)
GPIO.output(A5, GPIO.LOW)
GPIO.output(A6, GPIO.LOW)
GPIO.output(A7, GPIO.LOW)
GPIO.output(A8, GPIO.LOW)
GPIO.output(B1, GPIO.LOW)
GPIO.output(B2, GPIO.LOW)
GPIO.output(B3, GPIO.LOW)
GPIO.output(B4, GPIO.LOW)
GPIO.output(B5, GPIO.LOW)
GPIO.output(B6, GPIO.LOW)
GPIO.output(B7, GPIO.LOW)
GPIO.output(B8, GPIO.LOW)
    
@app.route("/")
def index():
    # Read Status and render info
    templateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,
    }

    return render_template('index.html', **templateData)
# parsing light button and setting gpio pins to correct setting 
@app.route("/light/<lightnumber>/<status>")
def setrelays(lightnumber, status):
    global lc1
    global lc2
    global lc3
    global lc4
    global lc5
    global lc6
    global lc7
    global lc8

    if lightnumber == 'light1':
            switch1 = A1
            switch2 = B1
            lc1 = status
    if lightnumber == 'light2':
            switch1 = A2
            switch2 = B2
            lc2 = status
    if lightnumber == 'light3':
            switch1 = A3
            switch2 = B3
            lc3 = status
    if lightnumber == 'light4':
            switch1 = A4
            switch2 = B4
            lc4 = status
    if lightnumber == 'light5':
            switch1 = A5
            switch2 = B5
            lc5 = status
    if lightnumber == 'light6':
            switch1 = A6
            switch2 = B6
            lc6 = status
    if lightnumber == 'light7':
            switch1 = A7
            switch2 = B7
            lc7 = status
    if lightnumber == 'light8':
            switch1 = A8
            switch2 = B8
            lc8 = status

    if status == "0": #off
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "1": #on low
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "2": #on medium
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "3": #on high
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)

        templateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,          
    }
             
    return render_template('index.html', **TemplateData)
# parsing light button and setting gpio pins to correct setting 
@app.route("/boxtimes/<boxnumber>/<time>")
def timerbtns(boxnumber,time):
    global time3
    global time2
    global time1
    global timeset

    timeset = time
    if boxnumber == '3':
        time3 = timeset
    if boxnumber == '2':
        time2 = timeset
    if boxnumber == '1':
        time1 = timeset

        TemplateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,
    }
    return render_template('index.html', **TemplateData)

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=80, debug=True)


'''
树莓皮GPIO状态与控制
'''
将RPi.GPIO导入为GPIO
从烧瓶导入烧瓶,呈现模板,请求
app=烧瓶(名称)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#定义GPIO
A1=13
A2=19
A3=26
A4=13
A5=19
A6=26
A7=13
A8=19
B1=26
B2=13
B3=19
B4=26
B5=26
B6=13
B7=19
B8=26
#初始化GPIO状态变量
lc1=3
lc2=3
lc3=3
lc4=3
lc5=3
lc6=3
lc7=3
lc8=3
#定义计时器变量
crnttime=0
timerstatus=0
#定义默认按钮时间
时间1=1200
时间2=1800
时间3=2400
#将led引脚定义为输出
GPIO.setup(A1,GPIO.OUT)
GPIO.setup(A2,GPIO.OUT)
GPIO.setup(A3,GPIO.OUT)
GPIO.setup(A4,GPIO.OUT)
GPIO.setup(A5,GPIO.OUT)
GPIO.setup(A6,GPIO.OUT)
GPIO.setup(A7,GPIO.OUT)
GPIO.setup(A8,GPIO.OUT)
GPIO.setup(B1,GPIO.OUT)
GPIO.setup(B2,GPIO.OUT)
GPIO.setup(B3,GPIO.OUT)
GPIO.setup(B4,GPIO.OUT)
GPIO.setup(B5,GPIO.OUT)
GPIO.setup(B6,GPIO.OUT)
GPIO.setup(B7,GPIO.OUT)
GPIO.setup(B8,GPIO.OUT)
#关闭LED
GPIO.输出(A1,GPIO.低)
GPIO.输出(A2,GPIO.低)
GPIO.输出(A3,GPIO.低)
GPIO.输出(A4,GPIO.低)
GPIO.输出(A5,GPIO.低)
GPIO.输出(A6,GPIO.低)
GPIO.输出(A7,GPIO.低)
GPIO.输出(A8,GPIO.低)
GPIO.输出(B1,GPIO.低)
GPIO.输出(B2,GPIO.低)
GPIO.output(B3,GPIO.LOW)
GPIO.输出(B4,GPIO.低)
GPIO.output(B5,GPIO.LOW)
GPIO.output(B6,GPIO.LOW)
GPIO.output(B7,GPIO.LOW)
GPIO.output(B8,GPIO.LOW)
@附件路线(“/”)
def index():
#读取状态和渲染信息
templateData={
“lc1”:lc1,
“lc2”:lc2,
“lc3”:lc3,
“lc4”:lc4,
“lc5”:lc5,
“lc6”:lc6,
"立法会七题":立法会七题,,
"立法会八题":立法会八题,,
“crnttime”:crnttime,
“timerstatus”:timerstatus,
“time1”:time1,
“time2”:time2,
“time3”:time3,
}
返回呈现模板('index.html',**templateData)
#解析灯按钮并将gpio引脚设置为正确设置
@应用路线(“/light/”)
def设置继电器(灯号、状态):
全球lc1
全球lc2
全球lc3
全球lc4
全球lc5
全球lc6
全球lc7
全球lc8
如果lightnumber==“light1”:
开关1=A1
开关2=B1
lc1=状态
如果lightnumber==“light2”:
开关1=A2
开关2=B2
lc2=状态
如果lightnumber==“light3”:
开关1=A3
开关2=B3
lc3=状态
如果lightnumber==“light4”:
开关1=A4
开关2=B4
lc4=状态
如果lightnumber==“light5”:
开关1=A5
开关2=B5
lc5=状态
如果lightnumber==“light6”:
开关1=A6
开关2=B6
lc6=状态
如果lightnumber==“light7”:
开关1=A7
开关2=B7
lc7=状态
如果lightnumber==“light8”:
开关1=A8
开关2=B8
lc8=状态
如果状态=“0”:#关闭
GPIO.输出(开关1,GPIO.高)
GPIO.输出(开关2,GPIO.高)
如果状态=“1”:#处于低位
GPIO.输出(开关1,GPIO.高)
GPIO.输出(开关2,GPIO.高)
如果状态==“2”:#中等
GPIO.输出(开关1,GPIO.高)
GPIO.输出(开关2,GPIO.高)
如果状态=“3”:#处于高位
GPIO.输出(开关1,GPIO.高)
GPIO.输出(开关2,GPIO.高)
templateData={
“lc1”:lc1,
“lc2”:lc2,
“lc3”:lc3,
“lc4”:lc4,
“lc5”:lc5,
“lc6”:lc6,
"立法会七题":立法会七题,,
"立法会八题":立法会八题,,
“crnttime”:crnttime,
“timerstatus”:timerstatus,
“time1”:time1,
“time2”:time2,
“time3”:time3,
}
返回呈现模板('index.html',**TemplateData)
#解析灯按钮并将gpio引脚设置为正确设置
@app.route(“/boxtimes/”)
def timerbtns(箱号、时间):
全球时间3
全球时间2
全球时间1
全球时间集
时间集=时间
如果boxnumber='3':
时间3=时间集
如果boxnumber==“2”:
时间2=时间集
如果boxnumber='1':
时间1=时间集
TemplateData={
“lc1”:lc1,
“lc2”:lc2,
“lc3”:lc3,
“lc4”:lc4,
“lc5”:lc5,
“lc6”:lc6,
"立法会七题":立法会七题,,
"立法会八题":立法会八题,,
“crnttime”:crnttime,
“timerstatus”:timerstatus,
“time1”:time1,
“time2”:time2,
“time3”:time3,
}
返回呈现模板('index.html',**TemplateData)
如果名称=“\uuuuu main\uuuuuuuu”:
app.run(host='0.0.0.0',port=80,debug=True)
我的问题是我做错了什么?a你好吗
@app.route("/light/<lightnumber>/<status>")
def setrelays(lightnumber, status):
    global lc1
    global lc2
    global lc3
    global lc4
    global lc5
    global lc6
    global lc7
    global lc8

    if lightnumber == 'light1':
            switch1 = A1
            switch2 = B1
            lc1 = status
    if lightnumber == 'light2':
            switch1 = A2
            switch2 = B2
            lc2 = status
    if lightnumber == 'light3':
            switch1 = A3
            switch2 = B3
            lc3 = status
    if lightnumber == 'light4':
            switch1 = A4
            switch2 = B4
            lc4 = status
    if lightnumber == 'light5':
            switch1 = A5
            switch2 = B5
            lc5 = status
    if lightnumber == 'light6':
            switch1 = A6
            switch2 = B6
            lc6 = status
    if lightnumber == 'light7':
            switch1 = A7
            switch2 = B7
            lc7 = status
    if lightnumber == 'light8':
            switch1 = A8
            switch2 = B8
            lc8 = status

    if status == "0": #off
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "1": #on low
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "2": #on medium
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "3": #on high
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)

        templateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,          
    }
             
    return render_template('index.html', **TemplateData)
192.168.0.19 - - [23/Apr/2021 22:06:14] "GET / HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:19] "GET /boxtimes/1/1140 HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:19] "GET /boxtimes/1/1080 HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:19] "GET /boxtimes/1/1020 HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:19] "GET /boxtimes/1/960 HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:20] "GET /boxtimes/1/900 HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:36] "GET /light/light1/3 HTTP/1.1" 200 -
192.168.0.19 - - [23/Apr/2021 22:06:37] "GET /light/light1/2 HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/pi/app/app.py", line 172, in setrelays
    return render_template('index.html', **templateData)
UnboundLocalError: local variable 'templateData' referenced before assignment

'''
    Raspberry Pi GPIO Status and Control
'''
import RPi.GPIO as GPIO
from flask import Flask, render_template, request
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#define actuators GPIOs
A1 = 13
A2 = 19
A3 = 26
A4 = 13
A5 = 19
A6 = 26
A7 = 13
A8 = 19
B1 = 26
B2 = 13
B3 = 19
B4 = 26
B5 = 26
B6 = 13
B7 = 19
B8 = 26
#initialize GPIO status variables
lc1 = 3
lc2 = 3
lc3 = 3
lc4 = 3
lc5 = 3
lc6 = 3
lc7 = 3
lc8 = 3
# Define timer Variables
crnttime = 0
timerstatus = 0
# Define default button times
time1 = 1200
time2 = 1800
time3 = 2400

# Define led pins as output
GPIO.setup(A1, GPIO.OUT)   
GPIO.setup(A2, GPIO.OUT) 
GPIO.setup(A3, GPIO.OUT)
GPIO.setup(A4, GPIO.OUT)   
GPIO.setup(A5, GPIO.OUT) 
GPIO.setup(A6, GPIO.OUT)
GPIO.setup(A7, GPIO.OUT)   
GPIO.setup(A8, GPIO.OUT) 
GPIO.setup(B1, GPIO.OUT)   
GPIO.setup(B2, GPIO.OUT) 
GPIO.setup(B3, GPIO.OUT)
GPIO.setup(B4, GPIO.OUT)   
GPIO.setup(B5, GPIO.OUT) 
GPIO.setup(B6, GPIO.OUT)
GPIO.setup(B7, GPIO.OUT)   
GPIO.setup(B8, GPIO.OUT) 
# turn leds OFF 
GPIO.output(A1, GPIO.LOW)
GPIO.output(A2, GPIO.LOW)
GPIO.output(A3, GPIO.LOW)
GPIO.output(A4, GPIO.LOW)
GPIO.output(A5, GPIO.LOW)
GPIO.output(A6, GPIO.LOW)
GPIO.output(A7, GPIO.LOW)
GPIO.output(A8, GPIO.LOW)
GPIO.output(B1, GPIO.LOW)
GPIO.output(B2, GPIO.LOW)
GPIO.output(B3, GPIO.LOW)
GPIO.output(B4, GPIO.LOW)
GPIO.output(B5, GPIO.LOW)
GPIO.output(B6, GPIO.LOW)
GPIO.output(B7, GPIO.LOW)
GPIO.output(B8, GPIO.LOW)
    
@app.route("/")
def index():
    # Read Status and render info
    templateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,
    }

    return render_template('index.html', **templateData)
# parsing light button and setting gpio pins to correct setting 
@app.route("/light/<lightnumber>/<status>")
def setrelays(lightnumber, status):
    global lc1
    global lc2
    global lc3
    global lc4
    global lc5
    global lc6
    global lc7
    global lc8

    if lightnumber == 'light1':
            switch1 = A1
            switch2 = B1
            lc1 = status
    if lightnumber == 'light2':
            switch1 = A2
            switch2 = B2
            lc2 = status
    if lightnumber == 'light3':
            switch1 = A3
            switch2 = B3
            lc3 = status
    if lightnumber == 'light4':
            switch1 = A4
            switch2 = B4
            lc4 = status
    if lightnumber == 'light5':
            switch1 = A5
            switch2 = B5
            lc5 = status
    if lightnumber == 'light6':
            switch1 = A6
            switch2 = B6
            lc6 = status
    if lightnumber == 'light7':
            switch1 = A7
            switch2 = B7
            lc7 = status
    if lightnumber == 'light8':
            switch1 = A8
            switch2 = B8
            lc8 = status

    if status == "0": #off
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "1": #on low
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "2": #on medium
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)
    if status == "3": #on high
        GPIO.output(switch1, GPIO.HIGH)
        GPIO.output(switch2, GPIO.HIGH)

        templateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,          
    }
             
    return render_template('index.html', **TemplateData)
# parsing light button and setting gpio pins to correct setting 
@app.route("/boxtimes/<boxnumber>/<time>")
def timerbtns(boxnumber,time):
    global time3
    global time2
    global time1
    global timeset

    timeset = time
    if boxnumber == '3':
        time3 = timeset
    if boxnumber == '2':
        time2 = timeset
    if boxnumber == '1':
        time1 = timeset

        TemplateData = {
              'lc1'  : lc1,
              'lc2'  : lc2,
              'lc3'  : lc3,
              'lc4'  : lc4,
              'lc5'  : lc5,
              'lc6'  : lc6,
              'lc7'  : lc7,
              'lc8'  : lc8,
              'crnttime'  : crnttime,
              'timerstatus'  : timerstatus,
              'time1'  : time1,
              'time2'  : time2,
              'time3'  : time3,
    }
    return render_template('index.html', **TemplateData)

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=80, debug=True)

    window.lc1 = {{ lc1  }};
    
    if (window.lc1 == 3){ 
    document.getElementById("llc1").style.backgroundColor = "transparent";
    };
    if (window.lc1 == 2){ 
    document.getElementById("mlc1").style.backgroundColor = "transparent"; 
    document.getElementById("llc1").style.backgroundColor = "transparent";
    };
    if (window.lc1 == 1){ 
    document.getElementById("slc1").style.backgroundColor = "transparent";
    document.getElementById("mlc1").style.backgroundColor = "transparent"; 
    document.getElementById("llc1").style.backgroundColor = "transparent";
    };
    if (window.lc1 == 0){ 
    document.getElementById("slc1").style.backgroundColor = "#DB402B";
    document.getElementById("mlc1").style.backgroundColor = "#DB402B";
    document.getElementById("llc1").style.backgroundColor = "#DB402B";
    };