-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring (WEB Server): refactored Web Server Handling
- introduces khoih-prog/WiFiWebServer Library - webserver handling is much cleaner now - splitted CSS and HTML - introduces a small JS File - HTML interface does not reload the whole page for new data - untroduces a small JSON interface which serves the states directly over the webserver - prepared some code for user authentification
- Loading branch information
Mario Lukas
committed
Dec 13, 2021
1 parent
886eaee
commit dc98c6c
Showing
12 changed files
with
659 additions
and
789 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ void setup() { | |
led_set_color(LED_WHITE); | ||
led_update(); | ||
|
||
|
||
modeButton.begin(); | ||
modeButton.read(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const char javascript[] PROGMEM = R"=====( | ||
var el = document.getElementById("ampel"); | ||
refreshAmpel(); | ||
setInterval(refreshAmpel, 10000); | ||
|
||
function clearAmpel(){ | ||
el.classList.remove("ampelgruen"); | ||
el.classList.remove("ampelgelb"); | ||
el.classList.remove("ampelrot"); | ||
el.classList.remove("ampelrotblinkend"); | ||
} | ||
|
||
function refreshAmpel() { | ||
var xmlhttp = new XMLHttpRequest(); | ||
var url = "sensors.json"; | ||
xmlhttp.onreadystatechange = function() { | ||
if (this.readyState == 4 && this.status == 200) { | ||
var state = JSON.parse(this.responseText); | ||
clearAmpel(); | ||
document.getElementById("state").innerHTML = "<b>Co2:</b> "+state.co2+" ppm<br><b>Temperature:</b> "+state.temp + " ºC<br><b>Illumination:</b> "+state.lux+" LUX <br><b>Humidity:</b> "+state.hum+" %<br><b>MQTT connected:</b> "+!!state.mqtt+"<br><br>Firmware: "+state.firmware; | ||
if (state.co2 < 800) { | ||
el.classList.add("ampelgruen"); | ||
} else if (state.co2 < 1000) { | ||
el.classList.add("ampelgelb"); | ||
} else if (state.co2 < 1200) { | ||
el.classList.add("ampelrot"); | ||
} else { | ||
el.classList.add("ampelrotblinkend"); | ||
} | ||
} | ||
}; | ||
xmlhttp.open("GET", url, true); | ||
xmlhttp.send(); | ||
} | ||
)====="; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
/** | ||
* Confirmation Page | ||
*/ | ||
|
||
const char save_settings_html[] PROGMEM = R"=====( | ||
<head> | ||
<meta charset=\"UTF-8\"> | ||
<title>CO2 Ampel Wifi Settings saved</title> | ||
<meta http-equiv=\"refresh\" content=\"3; URL=/\"> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="box">WiFi Settings saved.<br> Device will reboot soon. </div> | ||
</body> | ||
</html> | ||
)====="; | ||
|
||
|
||
/** | ||
* Settings Page | ||
*/ | ||
|
||
const char settings_header_html[] PROGMEM = R"=====( | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>CO2 Ampel Wifi Settings</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="box"> | ||
<form class="box" action="/save" method="POST" name="loginForm"> | ||
<h1>Settings</h1> | ||
)====="; | ||
|
||
const char settings_footer_html[] PROGMEM = R"=====( | ||
</div> | ||
</body> | ||
</html> | ||
)====="; | ||
|
||
|
||
/** | ||
* LogIn Page for Settings | ||
*/ | ||
|
||
|
||
const char login_html[] PROGMEM = R"=====( | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="box"> | ||
<form action="/login" method="POST"><br> | ||
Password:<input type="password" name="login_password" placeholder="password"><br> | ||
<input type="submit" name="SUBMIT" value="Submit"> | ||
</form> | ||
</div> | ||
<br> | ||
)====="; | ||
|
||
|
||
/** | ||
* Main HTML Page | ||
*/ | ||
const char root_html[] PROGMEM = R"=====( | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>CO2 Ampel Wifi AP</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
<link rel="stylesheet" href="ampel.css"> | ||
</head> | ||
<div class="box"><h1>CO2 Ampel State</h1> | ||
<span id="ampel" class="css-ampel %s"><span class="cssampelspan"></span></span> | ||
<br> | ||
<br> | ||
<span id="state">Waiting for initial state...</span> | ||
</div> | ||
<body></body></html> | ||
<script type="text/javascript" src="/scripts.js"></script> | ||
)====="; |
Oops, something went wrong.