-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
33 lines (29 loc) · 1023 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import Flask, render_template
from flask import request
import csv
import datetime
app = Flask(__name__)
valueBright = 0
state = 0
@app.route("/", methods=['GET', 'POST'])
def hello():
# Use global variable
global valueBright
global state
current_time = datetime.datetime.now()
timestamp = current_time.strftime("%Y-%m-%d %H:%M:%S")
# Update global value when req returns not none
if request.args.get("var") != None:
valueBright = request.args.get("var")
if request.args.get("state") != None:
state = request.args.get("state")
print("Brightness value:", valueBright)
filename = "data.csv"
with open (filename, "a", newline = "") as file:
writer = csv.writer(file)
writer.writerow([current_time, valueBright])
if (state == "0" ):
state_string = " Touch Sensor "
elif(state == "1"):
state_string = " Auto - Brightness "
return render_template("index.html", brightness = valueBright, switch = state_string)