added all info here
commit
b6156ae81d
|
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"username": "1",
|
||||||
|
"password": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"
|
||||||
|
}
|
||||||
|
]
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,109 @@
|
||||||
|
import socket, json, random
|
||||||
|
|
||||||
|
bufferSize = 1024
|
||||||
|
|
||||||
|
gets_data = {}
|
||||||
|
|
||||||
|
|
||||||
|
def initialize():
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
s.bind(('192.168.1.35', 7777))
|
||||||
|
s.settimeout(0.5)
|
||||||
|
with open('data.json') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
return [s, data]
|
||||||
|
|
||||||
|
def update_json(data):
|
||||||
|
with open('data.json', 'w') as f:
|
||||||
|
json.dump(data, f)
|
||||||
|
|
||||||
|
'''def get_smth(s, data):
|
||||||
|
req = {"SensorType": data}
|
||||||
|
while True:
|
||||||
|
print("Sending")
|
||||||
|
s.sendto(json.dumps(req).encode(), (('192.168.1.77', 7777)))
|
||||||
|
try:
|
||||||
|
a = s.recvfrom(bufferSize)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
j = json.loads(a[0].decode())
|
||||||
|
if data in j.get('SensorType'):
|
||||||
|
print(j.get("value"), True)
|
||||||
|
s.sendto("GOT".encode(), ('192.168.1.77', 7777))
|
||||||
|
else:
|
||||||
|
print(a[0].decode())
|
||||||
|
continue
|
||||||
|
except Exception as err:
|
||||||
|
print("lol", err, a[0].decode())
|
||||||
|
continue
|
||||||
|
|
||||||
|
#finally:
|
||||||
|
#print("lol")
|
||||||
|
def change_smth(s, data, value):
|
||||||
|
req = {"SensorType": data,
|
||||||
|
"value": value}
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
a = s.recvfrom(bufferSize)
|
||||||
|
j = json.loads(a[0].decode())
|
||||||
|
if data in j.get("SensorType"):
|
||||||
|
print(j[data], True)
|
||||||
|
return j[data]
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print(a[0].decode())
|
||||||
|
except Exception as err:
|
||||||
|
print(a)
|
||||||
|
continue
|
||||||
|
'''
|
||||||
|
|
||||||
|
def send_command(s, SensorType: str,command: str, value = None):
|
||||||
|
if value:
|
||||||
|
req = {"Command": command,
|
||||||
|
"SensorType": SensorType,
|
||||||
|
"Value": value}
|
||||||
|
else:
|
||||||
|
req = {"Command": command,
|
||||||
|
"SensorType": SensorType}
|
||||||
|
|
||||||
|
while True:
|
||||||
|
s.sendto(json.dumps(req).encode(), (('192.168.1.77', 7777)))
|
||||||
|
try:
|
||||||
|
a = s.recvfrom(bufferSize)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
response = json.loads(a[0].decode())
|
||||||
|
if command == 'GetValue' and response["SensorType"] == SensorType:
|
||||||
|
print(j.get("Value"), True)
|
||||||
|
elif command == 'ChangeValue' and response["SensorType"] == SensorType:
|
||||||
|
print("Changed to " + str(value), True)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
except Exception as err:
|
||||||
|
print("We've got an error: ", err, a[1])
|
||||||
|
|
||||||
|
|
||||||
|
def check_sos(s):
|
||||||
|
'''req = {"SensorType": "SOS"}
|
||||||
|
while True:
|
||||||
|
s.sendto(json.dumps(req).encode(), (('192.168.1.77', 7777)))
|
||||||
|
try:
|
||||||
|
a = s.recvfrom(bufferSize)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
j = json.loads(a[0].decode())
|
||||||
|
if data in j.get('SensorType'):
|
||||||
|
print(j.get("value"), True)
|
||||||
|
s.sendto("GOT".encode(), ('192.168.1.77', 7777))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print(a[0].decode())
|
||||||
|
continue
|
||||||
|
except Exception as err:
|
||||||
|
print("lol", err, a[0].decode())
|
||||||
|
continue
|
||||||
|
'''
|
||||||
|
return json.dumps([{"stationName": str(random.randint(1,255)), "alertType": 'alert!!'}, {"stationName": str(random.randint(1,255)), "alertType": 'alert2!!'}])
|
||||||
|
|
@ -0,0 +1,143 @@
|
||||||
|
import requests, random, hashlib, json, os
|
||||||
|
from esplistener.esplistener import *
|
||||||
|
from flask import session, Flask, request, render_template, url_for, redirect
|
||||||
|
|
||||||
|
initialize_data = initialize()
|
||||||
|
|
||||||
|
socket, data = initialize_data[0], initialize_data[1]
|
||||||
|
|
||||||
|
#get_smth(socket, "Temperature")
|
||||||
|
send_command(socket, "Temperature", "GetValue")
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.secret_key = '%TGHUI8uyFGHI(*&^5rUIO9i*&^TRfvgbHNJKLKJnhgfDE3WedFGhjKOlIuyTRe4567ioP:liuytr56&8()IuGTfrEdsXcghuy6'
|
||||||
|
|
||||||
|
|
||||||
|
def hash_data(data):
|
||||||
|
hashpass = hashlib.sha256()
|
||||||
|
hashpass.update(bytes(data, encoding='utf8'))
|
||||||
|
passw = hashpass.hexdigest()
|
||||||
|
return passw
|
||||||
|
|
||||||
|
def create_account(login, password):
|
||||||
|
login, password = str(login), str(password)
|
||||||
|
if not os.path.exists('accounts.json'):
|
||||||
|
data = []
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
with open('accounts.json', 'r') as file:
|
||||||
|
data = json.load(file)
|
||||||
|
for i in data:
|
||||||
|
if i['username'] == login:
|
||||||
|
print("found")
|
||||||
|
return 0
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
data = []
|
||||||
|
password_entry = {'username': login, 'password': hash_data(password)}
|
||||||
|
data.append(password_entry)
|
||||||
|
with open('accounts.json', 'w') as file:
|
||||||
|
json.dump(data, file, indent=4)
|
||||||
|
return 1
|
||||||
|
def login_into_account(session, login, password):
|
||||||
|
if not os.path.exists('accounts.json'):
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
with open('accounts.json', 'r') as file:
|
||||||
|
data = json.load(file)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
data = []
|
||||||
|
for entry in data:
|
||||||
|
if entry['username'] == login and entry['password'] == hash_data(password):
|
||||||
|
session['loggedin'], session['username'] = True, login
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def define_session(session):
|
||||||
|
if 'loggedin' not in session.keys():
|
||||||
|
session['loggedin'] = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_cur_speed(session):
|
||||||
|
if session['loggedin']:
|
||||||
|
return random.randint(1, 100)
|
||||||
|
return "no rights"
|
||||||
|
#return int(requests.post("http://"+ip+"/get_speed"))
|
||||||
|
#Основные страницы, индекс, и страницы лабораторий, авторизация
|
||||||
|
@app.route("/", methods = ["GET", "POST"])
|
||||||
|
def index():
|
||||||
|
define_session(session)
|
||||||
|
if session['loggedin'] == True:
|
||||||
|
cur_speed = 25
|
||||||
|
if request.method == "POST":
|
||||||
|
cur_speed = request.form.get("slide")
|
||||||
|
return render_template("mashinka.html", cur_speed = cur_speed)
|
||||||
|
return render_template("mashinka.html", cur_speed = cur_speed)
|
||||||
|
else:
|
||||||
|
return render_template("index.html")
|
||||||
|
|
||||||
|
@app.route('/register', methods = ["POST", "GET"])
|
||||||
|
def register():
|
||||||
|
if request.method == "GET":
|
||||||
|
if session['loggedin'] == True:
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("register.html", err = '')
|
||||||
|
else:
|
||||||
|
login = request.form.get('login')
|
||||||
|
passw = request.form.get('password')
|
||||||
|
if create_account(login, passw):
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("register.html", err='Такой пользователь уже существует')
|
||||||
|
|
||||||
|
@app.route('/login', methods = ["POST", "GET"])
|
||||||
|
def login():
|
||||||
|
if request.method == 'GET':
|
||||||
|
if session['loggedin'] == True:
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("login.html", err = '')
|
||||||
|
else:
|
||||||
|
login = request.form.get('login')
|
||||||
|
passw = request.form.get('password')
|
||||||
|
print(passw)
|
||||||
|
if login_into_account(session, login, passw):
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("login.html", err="Неверный логин/пароль")
|
||||||
|
|
||||||
|
#Общение с ЕСП
|
||||||
|
@app.route("/sos_check", methods = ["POST"])
|
||||||
|
def sos_check():
|
||||||
|
if random.randint(0,1):
|
||||||
|
return check_sos(socket)
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
@app.route("/mashinka_go", methods = ["POST"])
|
||||||
|
def mashinka_go():
|
||||||
|
if session['loggedin']:
|
||||||
|
return ''
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
@app.route("/mashinka_stop", methods = ["POST"])
|
||||||
|
def mashinka_stop():
|
||||||
|
if session['loggedin']:
|
||||||
|
return ''
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
@app.route("/get_temperature", methods = ["POST"])
|
||||||
|
def get_temperature():
|
||||||
|
if session['loggedin']:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"username": "1",
|
||||||
|
"password": "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "1",
|
||||||
|
"password": "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "1",
|
||||||
|
"password": "4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "2",
|
||||||
|
"password": "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"username": "skillissue",
|
||||||
|
"password": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Mashinka Control</title>
|
||||||
|
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||||
|
<!-- Google Fonts -->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">
|
||||||
|
<!-- MDB -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="#">Seal Team</a>
|
||||||
|
<span class="navbar-text">
|
||||||
|
Управление машинкой
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class=alertContainer id="alertcontainer"></div>
|
||||||
|
<center><h1>Вы не авторизированы</h1></center>
|
||||||
|
<div class="d-flex justify-content-center mt-5">
|
||||||
|
<button class="btn btn-primary btn-lg mr-3" class="update_form" type="button" onclick="document.location.href = '/login'">Авторизация</button>
|
||||||
|
|
||||||
|
<button class="btn btn-primary btn-lg ml-3" class="update_form" type="button" onclick="document.location.href = '/register'">Регистрация</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MDB -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
|
||||||
|
<!--Script-->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function callSOSCheckEndpoint() {
|
||||||
|
setInterval(function() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/sos_check',
|
||||||
|
method: 'POST',
|
||||||
|
success: function(data) {
|
||||||
|
if (data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
console.log(data);
|
||||||
|
var alertHTML = '<div class="alert alert-success alert-dismissible fade show" role="alert">'
|
||||||
|
var alertMessages = [];
|
||||||
|
|
||||||
|
// Iterate over the returned data
|
||||||
|
data.forEach(function(alertt) {
|
||||||
|
var statname = alertt["stationName"];
|
||||||
|
var sosAlertType = alertt["alertType"];
|
||||||
|
var alertMessage = 'SOS ALERT ON THIS STATIONS: ' + statname + ':' + sosAlertType;
|
||||||
|
alertMessages.push(alertMessage);
|
||||||
|
});
|
||||||
|
alertMessages.forEach(function(alertMessage) {
|
||||||
|
alertHTML += '<div class="alert alert-warning">' + alertMessage + '</div>';
|
||||||
|
});
|
||||||
|
alertHTML += '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'
|
||||||
|
var x = document.getElementById("alertcontainer");
|
||||||
|
x.innerHTML = alertHTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
callSOSCheckEndpoint();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// this is the id of the submit button
|
||||||
|
$(".update_form").click(function() {
|
||||||
|
var myform = $(this).closest("form"); //parent form
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "approve_test.php",
|
||||||
|
data: myform.serialize(), // serializes the form's elements.
|
||||||
|
success: function(data)
|
||||||
|
{
|
||||||
|
alert(data); // show response from the php script.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false; // avoid to execute the actual submit of the form.
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Mashinka Control</title>
|
||||||
|
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||||
|
<!-- Google Fonts -->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">
|
||||||
|
<!-- MDB -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.1.0/mdb.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="#">Seal Team: Авторизация</a>
|
||||||
|
<span class="navbar-buttons">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<button data-mdb-ripple-init type="button" class="btn btn-primary me-3">
|
||||||
|
Авторизация
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-center mt-5">
|
||||||
|
<form class="mr-3" action="login" method="post">
|
||||||
|
<div class="form-outline" data-mdb-input-init>
|
||||||
|
<input required id="login" name="login" type="text" id="formControlLg" class="form-control form-control-lg" />
|
||||||
|
<label class="form-label" for="formControlLg">Имя пользователя</label>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
<div class="form-outline" data-mdb-input-init>
|
||||||
|
<input required id="password" name="password" type="password" id="formControlLg" class="form-control form-control-lg" />
|
||||||
|
<label class="form-label" for="formControlLg">Пароль</label>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg ml-3">Авторизация</button>
|
||||||
|
</form>
|
||||||
|
{% if err != '' %}
|
||||||
|
<p><h3>{{err}}</h3></p>
|
||||||
|
{% endif%}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MDB -->
|
||||||
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.1.0/mdb.umd.min.js"></script>
|
||||||
|
<!--Script-->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<link rel ="stylesheet" href="style.css">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Mashinka controls</title>
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet" />
|
||||||
|
<!-- Google Fonts -->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
|
||||||
|
<!-- MDB -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/3.11.0/mdb.min.css" rel="stylesheet" />
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Seal Team</title>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||||
|
<!-- Navbar -->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="">Seal Team</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<span class="navbar-text">
|
||||||
|
Управление машинкой
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="row justify-content-start">
|
||||||
|
<div class="col-md-8 d-grid gap-2">
|
||||||
|
<form method="post" action="/">
|
||||||
|
<input id="slide" type="range" min="1" max="255" step="1" value="{{cur_speed}}" name="slide">
|
||||||
|
<div id="sliderAmount"></div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="d-grid gap-2 col-md-2" >
|
||||||
|
<form action="mashinka_go" method="post">
|
||||||
|
<button type="submit" class="btn btn-dark" data-mdb-ripple-init>Запуск</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid gap-2 col-md-2">
|
||||||
|
<form action="mashinka_stop" method="post">
|
||||||
|
<button type="submit" class="btn btn-dark" data-mdb-ripple-init>Стоп</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
@ -0,0 +1,187 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Mashinka Control</title>
|
||||||
|
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||||
|
<!-- Google Fonts -->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">
|
||||||
|
<!-- MDB -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="#">Seal Team</a>
|
||||||
|
<span class="navbar-text">
|
||||||
|
Управление машинкой
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class=alertContainer id="alertcontainer"></div>
|
||||||
|
<!-- Centered Buttons -->
|
||||||
|
<div class="d-flex justify-content-around mt-5">
|
||||||
|
<button class="btn btn-primary btn-lg mr-3" type="button" onclick="document.getElementById('form1').submit();">Запуск</button>
|
||||||
|
<p class="fw-medium fs-3" id="sliderAmount">{{cur_speed}}</p>
|
||||||
|
<button class="btn btn-primary btn-lg ml-3" type="button" onclick="document.getElementById('form2').submit();">Остановка</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Slider -->
|
||||||
|
<div class="container mt2-5">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3"></div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<form method="POST" action="/">
|
||||||
|
<input type="range" class="form-range" value="{{cur_speed}}" min="1" max="255" step="1" name="slide" id="slide">
|
||||||
|
</form>
|
||||||
|
<canvas id="LastTemp"></canvas/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3"><canvas id="myChart" style="max-width: 500px;"></canvas></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Forms -->
|
||||||
|
<form id="form1" action="mashinka_go" method="POST" style="display: none;"></form>
|
||||||
|
<form id="form2" action="mashinka_stop" method="POST" style="display: none;"></form>
|
||||||
|
<!-- MDB -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
|
||||||
|
<!--Script-->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
<script>
|
||||||
|
var slide = document.getElementById('slide'),
|
||||||
|
sliderDiv = document.getElementById("sliderAmount");
|
||||||
|
|
||||||
|
slide.onchange = function() {
|
||||||
|
sliderDiv.innerHTML = this.value;
|
||||||
|
$.post({
|
||||||
|
url: '/',
|
||||||
|
data: $('form').serialize(),
|
||||||
|
success: function(response){
|
||||||
|
console.log(response);
|
||||||
|
},
|
||||||
|
error: function(error){
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
(() => {
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
// Graphs
|
||||||
|
const ctx = document.getElementById('LastTemp')
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const myChart = new Chart(ctx, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: [
|
||||||
|
'Sunday',
|
||||||
|
'Monday',
|
||||||
|
'Tuesday',
|
||||||
|
'Wednesday',
|
||||||
|
'Thursday',
|
||||||
|
'Friday',
|
||||||
|
'Saturday'
|
||||||
|
],
|
||||||
|
datasets: [{
|
||||||
|
data: [
|
||||||
|
15339,
|
||||||
|
21345,
|
||||||
|
18483,
|
||||||
|
24003,
|
||||||
|
23489,
|
||||||
|
24092,
|
||||||
|
12034
|
||||||
|
],
|
||||||
|
lineTension: 0,
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
borderColor: '#007bff',
|
||||||
|
borderWidth: 4,
|
||||||
|
pointBackgroundColor: '#007bff'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
boxPadding: 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})()
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
function callSOSCheckEndpoint() {
|
||||||
|
setInterval(function() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/sos_check',
|
||||||
|
method: 'POST',
|
||||||
|
success: function(data) {
|
||||||
|
if (data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
console.log(data);
|
||||||
|
var alertHTML = '<div class="alert alert-success alert-dismissible fade show" role="alert">'
|
||||||
|
var alertMessages = [];
|
||||||
|
|
||||||
|
// Iterate over the returned data
|
||||||
|
data.forEach(function(alertt) {
|
||||||
|
var statname = alertt["stationName"];
|
||||||
|
var sosAlertType = alertt["alertType"];
|
||||||
|
var alertMessage = 'SOS ALERT ON THIS STATIONS: ' + statname + ':' + sosAlertType;
|
||||||
|
alertMessages.push(alertMessage);
|
||||||
|
});
|
||||||
|
alertMessages.forEach(function(alertMessage) {
|
||||||
|
alertHTML += '<div class="alert alert-warning">' + alertMessage + '</div>';
|
||||||
|
});
|
||||||
|
alertHTML += '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'
|
||||||
|
var x = document.getElementById("alertcontainer");
|
||||||
|
x.innerHTML = alertHTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
callSOSCheckEndpoint();
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
$('form1').submit(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
$.ajax({
|
||||||
|
url: '/mashinka_go',
|
||||||
|
type: 'post',
|
||||||
|
data:$('#myForm').serialize(),
|
||||||
|
success:function(){
|
||||||
|
// Whatever you want to do after the form is successfully submitted
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('form2').submit(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
$.ajax({
|
||||||
|
url: '/mashinka_stop',
|
||||||
|
type: 'post',
|
||||||
|
data:$('#myForm').serialize(),
|
||||||
|
success:function(){
|
||||||
|
// Whatever you want to do after the form is successfully submitted
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Mashinka Control</title>
|
||||||
|
|
||||||
|
<!-- Font Awesome -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||||
|
<!-- Google Fonts -->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">
|
||||||
|
<!-- MDB -->
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.1.0/mdb.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="#">Seal Team: Регистрация</a>
|
||||||
|
<span class="navbar-buttons">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<button data-mdb-ripple-init type="button" class="btn btn-primary me-3">
|
||||||
|
Авторизация
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-center mt-5">
|
||||||
|
<form class="mr-3" action="register" method="post">
|
||||||
|
<div class="form-outline" data-mdb-input-init>
|
||||||
|
<input required id="login" name="login" type="text" id="formControlLg" class="form-control form-control-lg" />
|
||||||
|
<label class="form-label" for="formControlLg">Имя пользователя</label>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
<div class="form-outline" data-mdb-input-init>
|
||||||
|
<input required id="password" name="password" type="password" id="formControlLg" class="form-control form-control-lg" />
|
||||||
|
<label class="form-label" for="formControlLg">Пароль</label>
|
||||||
|
</div>
|
||||||
|
<p></p>
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg ml-3">Регистрация</button>
|
||||||
|
</form>
|
||||||
|
{% if err != '' %}
|
||||||
|
<p><h3>{{err}}</h3></p>
|
||||||
|
{% endif%}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MDB -->
|
||||||
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/7.1.0/mdb.umd.min.js"></script>
|
||||||
|
<!--Script-->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
no rights
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
from flask import Flask, request, redirect, url_for, render_template, json, render_template_string, jsonify
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
|
def control_panel():
|
||||||
|
print('request.form:', request.form)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
if request.form.get('button') == 'button-play':
|
||||||
|
print("play button pressed")
|
||||||
|
|
||||||
|
elif request.form.get('button') == 'button-exit':
|
||||||
|
print("exit button pressed")
|
||||||
|
|
||||||
|
elif request.form.get('slide'):
|
||||||
|
volume = request.form.get('slide')
|
||||||
|
print('volume:', volume)
|
||||||
|
#return jsonify({'volume': volume})
|
||||||
|
return json.dumps({'volume': volume})
|
||||||
|
|
||||||
|
print('render')
|
||||||
|
return render_template_string('''<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<!-- Required meta tags -->
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
||||||
|
|
||||||
|
<title>Slider</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container" id="control_panel_1">
|
||||||
|
<form action="/" method ="post" enctype="multipart/form-data" id="form">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<button class="btn btn-primary" button type="submit" name="button" value="button-play">PLAY</button>
|
||||||
|
|
||||||
|
<button class="btn btn-primary" button type="submit" name="button" value="button-exit">EXIT</button>
|
||||||
|
|
||||||
|
<input id="slide" type="range" min="1" max="100" step="1" value="10" name="slide">
|
||||||
|
<div id="sliderAmount"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!--- SCRIPTS --->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
var slide = document.getElementById('slide'),
|
||||||
|
sliderDiv = document.getElementById("sliderAmount");
|
||||||
|
|
||||||
|
slide.onchange = function() {
|
||||||
|
sliderDiv.innerHTML = this.value;
|
||||||
|
$.post({
|
||||||
|
url: '/',
|
||||||
|
data: $('form').serialize(),
|
||||||
|
success: function(response){
|
||||||
|
alert(response);
|
||||||
|
alert(response.volume); // works with jsonify()
|
||||||
|
alert(JSON.parse(response).volume); // works with json.dumps()
|
||||||
|
console.log(response);
|
||||||
|
},
|
||||||
|
error: function(error){
|
||||||
|
alert(response);
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>''')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True, use_reloader=False)
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from flask import Flask, render_template, url_for, redirect, request, json
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
app.secret_key = '%TGHUI8uyFGHI(*&^5rUIO9i*&^TRfvgbHNJKLKJnhgfDE3WedFGhjKOlIuyTRe4567ioP:liuytr56&8()IuGTfrEdsXcghuy6'
|
||||||
|
|
||||||
|
print("OPEN YOUR ESP SERIAL PORT READER A AND ENDER IP")
|
||||||
|
ip = input()
|
||||||
|
|
||||||
|
def hash_data(data):
|
||||||
|
hashpass = hashlib.sha256()
|
||||||
|
hashpass.update(bytes(password, encoding='utf8'))
|
||||||
|
passw = hashpass.hexdigest()
|
||||||
|
return passw
|
||||||
|
|
||||||
|
def create_account(login, password):
|
||||||
|
passw = hash_data(password)
|
||||||
|
data = {'username': login, 'password': passw}
|
||||||
|
with open('accounts.json', 'rw') as f:
|
||||||
|
for entry in json.load(f):
|
||||||
|
if entry['username'] == login:
|
||||||
|
return 0
|
||||||
|
json.dump(data, f)
|
||||||
|
return 1
|
||||||
|
def login_into_account(session, login, password):
|
||||||
|
passw = hash_data(password)
|
||||||
|
with open('accounts.json', 'r') as f:
|
||||||
|
for entry in json.load(f):
|
||||||
|
if entry['username'] == login and entry["password"] == password:
|
||||||
|
session['loggedin'], session['username'] = True, login
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
return requests.get("http://"+ip+"/status").text
|
||||||
|
|
||||||
|
@app.route('/', methods = ["GET", "POST"])
|
||||||
|
def index():
|
||||||
|
if session["loggedin"] == True:
|
||||||
|
stat = get_status().split()
|
||||||
|
led_status = int(stat[0])
|
||||||
|
led_brightness = int(stat[1])
|
||||||
|
if request.method == "POST":
|
||||||
|
if request.form.get("slide"):
|
||||||
|
brightness = request.form.get("slide")
|
||||||
|
print(brightness)
|
||||||
|
led_britghtness = change(brightness)
|
||||||
|
return render_template("index.html", led_status = led_status, led_brightness = led_brightness)
|
||||||
|
else:
|
||||||
|
return render_template("unauthorized.html")
|
||||||
|
|
||||||
|
@app.route('/register', methods = ["POST", "GET"])
|
||||||
|
def register():
|
||||||
|
if request.method == "GET":
|
||||||
|
if session['loggedin'] == True:
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("register.html")
|
||||||
|
else:
|
||||||
|
data = request.args
|
||||||
|
login = data['login']
|
||||||
|
passw = data['password']
|
||||||
|
if create_account(login, passw):
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("register.html", err='Такой пользователь уже существует')
|
||||||
|
|
||||||
|
@app.route('/login', methods = ["POST", "GET"])
|
||||||
|
def login():
|
||||||
|
if request.method == 'GET':
|
||||||
|
if session['loggedin'] == True:
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("login.html")
|
||||||
|
else:
|
||||||
|
data = request.args
|
||||||
|
login = data['login']
|
||||||
|
passw = data['passw']
|
||||||
|
if login_into_account(session, login, passw):
|
||||||
|
return redirect('/')
|
||||||
|
else:
|
||||||
|
return render_template("login.html", err="Неверный логин/пароль")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.ru()
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
|
||||||
|
|
||||||
|
ESP8266WebServer server(80);//Создадим веб сервер на 80 порту
|
||||||
|
bool LEDstatus = LOW;
|
||||||
|
byte led_brightness = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);// Настроим частоту Serial порта
|
||||||
|
delay(100);
|
||||||
|
pinMode(3, OUTPUT);// Настроим ножку светодиода на выход, чтобы управлять им
|
||||||
|
|
||||||
|
Serial.println("Connecting to ");
|
||||||
|
Serial.println("node");
|
||||||
|
//connect to your local wi-fi network
|
||||||
|
WiFi.mode(WIFI_STA);// Режим подключения к сторонней сети wi-fi
|
||||||
|
WiFi.begin("adm2", "98765432110");
|
||||||
|
// Ждем пока статус соеденения не будет равен WL_CONNECTED , что означает что еsp успешно подключена к сети
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(1000);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("WiFi connected..!");
|
||||||
|
Serial.print("Got IP: "); Serial.println(WiFi.localIP());// Вывод ip esp
|
||||||
|
//Настройка путей и их обработчиков
|
||||||
|
server.on("/status", handle_status);
|
||||||
|
server.on("/ledon", HTTPMethod::HTTP_POST, handle_ledon);
|
||||||
|
server.on("/ledoff", HTTPMethod::HTTP_POST, handle_ledoff);
|
||||||
|
//Настройка обработчика ненайденного пути
|
||||||
|
server.on("/slider", HTTPMethod::HTTP_POST, handle_slider);
|
||||||
|
server.onNotFound(handle_NotFound);
|
||||||
|
//Запуск сервера
|
||||||
|
server.begin();
|
||||||
|
Serial.println("HTTP server started");
|
||||||
|
}
|
||||||
|
void loop() {
|
||||||
|
//Обработка запросов
|
||||||
|
server.handleClient();
|
||||||
|
//Включение/Выключение светодиода. Помните у esp инвертированная логика светодиода на плате, поэтому LOW означает включить светодиод
|
||||||
|
/*if(LEDstatus)
|
||||||
|
{analogWrite(6, LOW);}
|
||||||
|
else
|
||||||
|
{analogWrite(6, HIGH);}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_status() {
|
||||||
|
Serial.println("LED: ");
|
||||||
|
Serial.println(LEDstatus);
|
||||||
|
//Отправка
|
||||||
|
server.send(200, "text/plain", String(not(LEDstatus))+" "+String(led_brightness));}
|
||||||
|
|
||||||
|
void handle_slider(){
|
||||||
|
if(!server.hasArg("brightness") or floor(atof(server.arg("brightness").c_str())) <= 0 or floor(atof(server.arg("brightness").c_str())) >= 256 ){
|
||||||
|
server.send(400, "texp/plain", "Brightness argument must be 0<br<256");
|
||||||
|
}else{
|
||||||
|
led_brightness = floor(atof(server.arg("brightness").c_str()));
|
||||||
|
analogWrite(3, led_brightness);
|
||||||
|
server.send(200, "texp/plain", "Changed brightness to "+String(led_brightness));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void handle_ledon() {
|
||||||
|
if( ! server.hasArg("timeout")){
|
||||||
|
LEDstatus = 0;
|
||||||
|
led_brightness = (server.hasArg("brightness") and floor(atof(server.arg("brightness").c_str())) < 256 and floor(atof(server.arg("brightness").c_str())) > 0) ? floor(atof(server.arg("brightness").c_str())) : 255;
|
||||||
|
analogWrite(3, led_brightness);
|
||||||
|
server.send(200, "text/plain", String(not(LEDstatus)));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
Serial.println("LED: 1");
|
||||||
|
Serial.println(server.arg("timeout").c_str());
|
||||||
|
LEDstatus = 0;
|
||||||
|
analogWrite(3, 255);
|
||||||
|
|
||||||
|
delay(atof(server.arg("timeout").c_str())*1000);
|
||||||
|
//Отправка
|
||||||
|
LEDstatus = 1;
|
||||||
|
analogWrite(3, 0);
|
||||||
|
server.send(200, "text/plain", String(not(LEDstatus))); //
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_ledoff() {
|
||||||
|
|
||||||
|
|
||||||
|
if( ! server.hasArg("timeout")){
|
||||||
|
LEDstatus = 1;
|
||||||
|
led_brightness = 0;
|
||||||
|
analogWrite(3, led_brightness);
|
||||||
|
server.send(200, "text/plain", String(not(LEDstatus)));
|
||||||
|
}else{
|
||||||
|
|
||||||
|
Serial.println("LED: 0");
|
||||||
|
Serial.println(server.arg("timeout").c_str());
|
||||||
|
LEDstatus = 1;
|
||||||
|
analogWrite(3, 0);
|
||||||
|
delay(atof(server.arg("timeout").c_str())*1000);
|
||||||
|
//Отправка
|
||||||
|
LEDstatus = 0;
|
||||||
|
analogWrite(3, led_brightness);
|
||||||
|
server.send(200, "text/plain", String(not(LEDstatus))); //Код состояния 200 - OK, тип - text/plain, cами данные - String(LEDstatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Код состояния 200 - OK, тип - text/plain, cами данные - String(LEDstatus)
|
||||||
|
void handle_NotFound(){
|
||||||
|
//Отправка
|
||||||
|
server.send(404, "text/plain", "Not found"); //Код состояния 404 - не найдено, тип - text/plain, cами данные - "Not found"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue