Async blink

This commit is contained in:
ABelliqueux 2022-10-25 12:50:56 +02:00
parent 9a46b193b1
commit 60b75eb4d8
1 changed files with 10 additions and 7 deletions

17
app.py
View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, time, subprocess, toml
import os, time, subprocess, threading, toml
from flask import Flask, flash, request, redirect, url_for
# HTTP auth
from flask_httpauth import HTTPBasicAuth
@ -81,7 +81,6 @@ def blinkPy():
# ~ os.system('echo none | sudo tee /sys/class/leds/led1/trigger')
# Blink 10 times
for j in range(16):
# TODO : add dd to NOPASSWD in /etc/sudoers.d/010...
led(0, 1)
led(1, 0)
time.sleep(.2)
@ -95,8 +94,10 @@ def blinkPy():
led(1, 0)
return "OK"
def threadBlink():
th=threading.Thread(target=blinkPy)
th.start()
@app.route("/")
@auth.login_required
def main():
@ -104,13 +105,14 @@ def main():
@app.route("/rssi")
@auth.login_required
def signal():
def rssi():
return getRSSI()
@app.route("/blink")
@auth.login_required
def blink():
return blinkPy()
threadBlink()
return "Blinkin"
@app.route("/reboot")
@auth.login_required
@ -124,7 +126,7 @@ def reboot():
def shutdown():
stdout = subprocess.run(["sudo", "/usr/sbin/poweroff"], capture_output=True)
print(stdout)
return "Shuting down..."
return "Shutting down..."
# File upload
@ -147,6 +149,7 @@ def upload_file():
return "OK"
if __name__ == '__main__':
# Turn ACT and POW leds off on start
ledSetup()
# app.run()
serve(app, host='127.0.0.1', port=5000, url_scheme='https')