init
This commit is contained in:
commit
a83250f8b4
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
import os, time, subprocess
|
||||
from flask import Flask
|
||||
# HTTP auth
|
||||
from flask_httpauth import HTTPBasicAuth
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
# HTTP Serve
|
||||
from waitress import serve
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
auth = HTTPBasicAuth()
|
||||
users = {
|
||||
"": generate_password_hash("secret"),
|
||||
}
|
||||
|
||||
@auth.verify_password
|
||||
def verify_password(username, password):
|
||||
if username in users and check_password_hash(users.get(username), password):
|
||||
return username
|
||||
|
||||
local_bin="/home/pi/.local/bin/"
|
||||
signal = 0
|
||||
|
||||
DEBUG = 0
|
||||
|
||||
# Get Wifi signal level
|
||||
def getRSSI():
|
||||
signal = subprocess.run( local_bin + "get_rssi.sh", capture_output=True)
|
||||
signal = str(signal.stdout, 'UTF-8')[:-1][1:]
|
||||
#print(signal)
|
||||
return signal
|
||||
|
||||
# Blink the Pi led to allow identification
|
||||
def blinkPy():
|
||||
for j in range(10):
|
||||
os.system('echo 1 | sudo dd status=none of=/sys/class/leds/led0/brightness > /dev/null 2>&1') # led on
|
||||
time.sleep(.2)
|
||||
os.system('echo 0 | sudo dd status=none of=/sys/class/leds/led0/brightness > /dev/null 2>&1') # led off
|
||||
time.sleep(.2)
|
||||
return "OK"
|
||||
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@auth.login_required
|
||||
def main():
|
||||
return "Nothing to see here !"
|
||||
|
||||
@app.route("/rssi")
|
||||
@auth.login_required
|
||||
def signal():
|
||||
return getRSSI()
|
||||
|
||||
@app.route("/blink")
|
||||
@auth.login_required
|
||||
def blink():
|
||||
return blinkPy()
|
||||
|
||||
@app.route("/reboot")
|
||||
@auth.login_required
|
||||
def reboot():
|
||||
stdout = subprocess.run(["sudo", "/usr/sbin/reboot"], capture_output=True)
|
||||
print(stdout)
|
||||
return "Rebooting..."
|
||||
|
||||
@app.route("/poweroff")
|
||||
@auth.login_required
|
||||
def shutdown():
|
||||
stdout = subprocess.run(["sudo", "/usr/sbin/poweroff"], capture_output=True)
|
||||
print(stdout)
|
||||
return "Shuting down..."
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
#serve(app, host='0.0.0.0', port=8181)
|
Loading…
Reference in New Issue