def css(request): """css is used to link the css file. :return: css file """ return send_file('./static/layout.css')
def index(request): form_cookie = None message_cookie = None if request.method == 'POST': form_cookie = '{pin},{pull}'.format(pin=request.form['pin'], pull=request.form['pull']) if 'read' in request.form: pull = None if request.form['pull'] == 'pullup': pull = machine.Pin.PULL_UP elif request.form['pull'] == 'pulldown': pull = machine.Pin.PULL_DOWN pin = machine.Pin(int(request.form['pin']), machine.Pin.IN, pull) message_cookie = 'Input pin {pin} is {state}.'.format( pin=request.form['pin'], state='high' if pin.value() else 'low') else: pin = machine.Pin(int(request.form['pin']), machine.Pin.OUT) value = 0 if 'set-low' in request.form else 1 pin.value(value) message_cookie = 'Output pin {pin} is now {state}.'.format( pin=request.form['pin'], state='high' if value else 'low') response = redirect('/') else: if 'message' not in request.cookies: message_cookie = 'Select a pin and an operation below.' response = send_file('gpio.html') if form_cookie: response.set_cookie('form', form_cookie) if message_cookie: response.set_cookie('message', message_cookie) return response
def mode3(request): if request.method == 'POST': print("received m-3 : ", request.form.get('on-off')) print("time : ", request.form.get('time')) print("colors : ", request.form.get("colors")) response = send_file("./templates/mode-3.html") return response
def mode1(request): if request.method == 'POST': print("received m-1 : ", request.form.get('on-off')) print("colors : ", request.form.get("colors")) print("light : ", request.form.get("light")) response = send_file("./templates/mode-1.html") return response
def mode2(request): if request.method == 'POST': print("received m-2 : ", request.form.get('on-off')) print("min s : ", request.form.get('min-s')) print("max s : ", request.form.get('max-s')) print("colors : ", request.form.get("colors")) print("light : ", request.form.get("light")) response = send_file("./templates/mode-2.html") return response
def index(request): #form_cookie= None #message_cookie = None if request.method == "GET": #print(dir(request)) #print(request.form) #print(request.headers) return Response(body=self.build_html_form(), headers={"Content-Type": "text/html"}) elif request.method == "POST": if request.form.get('save', None): ## they clicked save config. write the dict to flash as a json file... print(request.form) new_config = { "wifi": { "ssid": request.form['ssid'], "passphrase": request.form['passphrase'] }, "location": { "lat": request.form['lat'], "lng": request.form['lng'] }, "time": { "sunrise_offset": request.form['sunrise_offset'], "sunset_offset": request.form['sunset_offset'] }, "pushover": { "app_token": request.form['app_token'], "group_key": request.form['group_key'] }, "motor_tuning": { "motor_min": request.form['motor_min'], "motor_max": request.form['motor_max'], "ramp_steps": request.form['ramp_steps'], "ramp_time": request.form['ramp_time'], } } print(new_config) with open("config.json", 'w', encoding='utf-8') as f: print("Saving configuration to config.json...") f.write(json.dumps(new_config)) print("Done!") self.json_config = new_config return Response(body=self.build_html_form( message="Updated Configuration!"), headers={"Content-Type": "text/html"}) elif request.form.get('reset', None): ## They clicked on reset! Reset the device! self.update_reset_scheduled = True return send_file('reset.html')
def settings(request): response = send_file("./templates/settings.html") return response
def info(request): response = send_file("./templates/info.html") return response
def accueil(request): response = send_file("./templates/accueil.html") return response
def index(request): return send_file('static/index.html')
def static(request, path): if '..' in path: # directory traversal is not allowed return 'Not found', 404 return send_file('static/' + path)
def logo(request): return send_file('static/wesp32-logo.jpg')