put css into HTMLheader so it is always available. especially for WebRestart()

This commit is contained in:
Marcus 2024-04-17 19:41:10 +02:00
parent 19cd6c1288
commit 4fb0a6fdb7

View file

@ -163,28 +163,9 @@ const char HTMLheader[] PROGMEM = R"EOF(
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CanGrow</title> <title>CanGrow</title>
<link rel="stylesheet" href="/style.css"> <!-- <link rel="stylesheet" href="/style.css"> -->
</head> <style>
<body> /* Having the whole CSS here ensures it's all the time present*/
<ul class="nav">
<li><a href="/">CanGrow</a></li>
<li><a id="growSettings" href="/growSettings">Grow settings</a></li>
<li><a id="systemSettings" href="/systemSettings">System settings</a></li>
<li><a href="/wifiSettings">WiFi settings</a></li>
<li><a href="/help">Help</a></li>
<li><span id="GrowName"></span></li>
</ul>
<div class="center">
)EOF";
const char HTMLfooter[] PROGMEM = R"EOF(
</div>
</body>
</html>
)EOF";
const char HTMLstyleCSS[] PROGMEM = R"EOF(
body { body {
color: #cae0d0; color: #cae0d0;
background-color: #1d211e; background-color: #1d211e;
@ -274,11 +255,37 @@ a:active {
.nav li a:active { .nav li a:active {
color: #cae0d0; color: #cae0d0;
} }
</style>
</head>
<body>
<ul class="nav">
<li><a href="/">CanGrow</a></li>
<li><a id="growSettings" href="/growSettings">Grow settings</a></li>
<li><a id="systemSettings" href="/systemSettings">System settings</a></li>
<li><a href="/wifiSettings">WiFi settings</a></li>
<li><a href="/help">Help</a></li>
<li><span id="GrowName"></span></li>
</ul>
<div class="center">
)EOF"; )EOF";
const char HTMLfooter[] PROGMEM = R"EOF(
</div>
</body>
</html>
)EOF";
/*
* I decided to embed CSS into HTMLheader because after
* a wifi change triggerd restart of the esp, the the style.css never get deliverd
* because the esp restarts after the webpage was delivered. style.css would be a second call
* but when the browser sends this, it's too late.
const char HTMLstyleCSS[] PROGMEM = R"EOF(
)EOF";
*/
const char HTMLsuccess[] PROGMEM = R"EOF( const char HTMLsuccess[] PROGMEM = R"EOF(
<div class='infomsg'>Successfully saved!</div> <div class='infomsg'>Successfully saved!</div>
)EOF"; )EOF";
@ -952,7 +959,7 @@ void WebHandler() {
* WebHandler_unconfigured() and WebHandler_configured() * WebHandler_unconfigured() and WebHandler_configured()
*/ */
// style.css // style.css
webserver.on("/style.css", HTTP_GET, WEBstyleCSS); //webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// Web root // Web root
webserver.on("/", HTTP_GET, WEBroot); webserver.on("/", HTTP_GET, WEBroot);
@ -985,8 +992,8 @@ void WebHandler() {
} }
void WebRestart() { void WebRestart() {
if(NeedRestart == true) {
String body = FPSTR(HTMLheader); String body = FPSTR(HTMLheader);
if(NeedRestart == true) {
body += "<h1>Restarting</h1>"; body += "<h1>Restarting</h1>";
body += "<div class='infomsg'>After restart you will be connected to Wifi<br><b>"; body += "<div class='infomsg'>After restart you will be connected to Wifi<br><b>";
body += WIFIssid; body += WIFIssid;
@ -996,6 +1003,10 @@ void WebRestart() {
Serial.println("Restarting... see you soon space cowboy!"); Serial.println("Restarting... see you soon space cowboy!");
delay(1000); delay(1000);
ESP.restart(); ESP.restart();
} else {
body += "<div class='warnmsg'><h1>Not allowed</h1></div>";
body += returnHTMLfooter();
webserver.send(405, "text/html", body);
} }
} }
@ -1071,13 +1082,15 @@ String returnStrSelected(byte savedValue, byte selectId) {
*/ */
// not really a webpage, but CSS is important for them :p // not really a webpage, but CSS is important for them :p
/*
void WEBstyleCSS() { void WEBstyleCSS() {
webserver.send(200, "text/css", HTMLstyleCSS); webserver.send(200, "text/css", HTMLstyleCSS);
} }
*/
void WEB404() { void WEB404() {
String body = FPSTR(HTMLheader); String body = FPSTR(HTMLheader);
body += "<h1>404 - not found</h1>"; body += "<div class='warnmsg'><h1>404 - not found</h1></div>";
body += returnHTMLfooter(); body += returnHTMLfooter();
webserver.send(404, "text/html", body); webserver.send(404, "text/html", body);
} }