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

15
app.py
View File

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