firmware wip - replace double quotes with single ones , its less confusing for geany ide

This commit is contained in:
Marcus 2024-04-30 20:02:46 +02:00
parent 805ec41ffd
commit 0f8ff91d37

View file

@ -86,8 +86,8 @@ IPAddress WIFIip(192,168,4,20);
IPAddress WIFInetmask(255,255,255,0); IPAddress WIFInetmask(255,255,255,0);
IPAddress WIFIgateway(192,168,4,254); IPAddress WIFIgateway(192,168,4,254);
IPAddress WIFIdns(0,0,0,0); IPAddress WIFIdns(0,0,0,0);
char WebUiUsername[16] = "cangrow"; //char WebUiUsername[16] = "cangrow";
char WebUiPassword[32] = "cangrow"; //char WebUiPassword[32] = "cangrow";
// //
// System // System
@ -166,6 +166,9 @@ ESP8266WebServer webserver(80);
/* /*
* HTML constants for header, footer, css, ... * HTML constants for header, footer, css, ...
* Note: I know of the existence of SPIFFS and ESPHtmlTemplateProcessor,
* but to keep things simple for compiling and upload for others, I decided
* to not use those.
*/ */
// Template: const char HTMLexamplepage[] PROGMEM = R"EOF()EOF"; // Template: const char HTMLexamplepage[] PROGMEM = R"EOF()EOF";
@ -173,10 +176,10 @@ const char HTMLheader[] PROGMEM = R"EOF(
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<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'> -->
<style> <style>
/* Having the whole CSS here ensures it's all the time present*/ /* Having the whole CSS here ensures it's all the time present*/
body { body {
@ -257,7 +260,7 @@ const char HTMLheader[] PROGMEM = R"EOF(
.nav li a , .nav span { .nav li a , .nav span {
color: #ddd; color: #ddd;
display: block; display: block;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
font-size:0.8em; font-size:0.8em;
padding: 10px 20px; padding: 10px 20px;
text-decoration: none; text-decoration: none;
@ -284,7 +287,7 @@ const char HTMLheader[] PROGMEM = R"EOF(
</style> </style>
<script> <script>
function highlightActiveMenu(menuEntry) { function highlightActiveMenu(menuEntry) {
document.getElementById(menuEntry).classList.add("activeMenu"); document.getElementById(menuEntry).classList.add('activeMenu');
} }
function replaceStr(dst, content) { function replaceStr(dst, content) {
@ -293,16 +296,16 @@ const char HTMLheader[] PROGMEM = R"EOF(
</script> </script>
</head> </head>
<body> <body>
<ul class="nav"> <ul class='nav'>
<li><a id="MenuGrowName" href="/">&#x1F331; CanGrow</a></li> <li><a id='MenuGrowName' href='/'>&#x1F331; CanGrow</a></li>
<li><a id="MgrowSettings" href="/growSettings">Grow settings</a></li> <li><a id='MgrowSettings' href='/growSettings'>Grow settings</a></li>
<li><a id="MsystemSettings" href="/systemSettings">System settings</a></li> <li><a id='MsystemSettings' href='/systemSettings'>System settings</a></li>
<li><a id="MwifiSettings" href="/wifiSettings">WiFi settings</a></li> <li><a id='MwifiSettings' href='/wifiSettings'>WiFi settings</a></li>
<li><a id="Mhelp" href="/help">Help</a></li> <li><a id='Mhelp' href='/help'>Help</a></li>
<li><span id="MenuTime" class="MenuTime"></span></li> <li><span id='MenuTime' class='MenuTime'></span></li>
<li><a id="CanGrowVer" href='https://git.la10cy.net/DeltaLima/CanGrow' target="_blank">CanGrow</a></li> <li><a id='CanGrowVer' href='https://git.la10cy.net/DeltaLima/CanGrow' target='_blank'>CanGrow</a></li>
</ul> </ul>
<div class="center"> <div class='center'>
)EOF"; )EOF";
@ -312,15 +315,6 @@ const char HTMLfooter[] PROGMEM = R"EOF(
</html> </html>
)EOF"; )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>
@ -328,8 +322,8 @@ const char HTMLsuccess[] PROGMEM = R"EOF(
const char HTMLneedRestart[] PROGMEM = R"EOF( const char HTMLneedRestart[] PROGMEM = R"EOF(
<div class='warnmsg'>Restart is required to apply new WiFi settings! <div class='warnmsg'>Restart is required to apply new WiFi settings!
<form action="/system/restart"> <form action='/system/restart'>
<input type="submit" value="Restart now" /> <input type='submit' value='Restart now' />
</form> </form>
</div> </div>
)EOF"; )EOF";
@ -1290,6 +1284,44 @@ void WebHandler() {
* return functions, they return things for the web stuff * return functions, they return things for the web stuff
*/ */
String returnHTMLheader(String MenuEntry = "") {
String header;
header += FPSTR(HTMLheader);
// print actual time in header
//~ footer += "<script>replaceStr('CanGrowVer', 'CanGrow v";
//~ footer += CanGrowVer;
//~ footer += "');\n";
//~ footer += "replaceStr('MenuTime', '";
//~ footer += timeClient.getFormattedTime();
//~ footer += "');\n";
//~ footer += "highlightActiveMenu('M";
//~ footer += MenuEntry;
//~ footer += "');";
//~ footer += "</script>";
//~ // show the GrowName in the menu if set
//~ if(strlen(GrowName) > 0){
//~ footer += "<script>replaceStr('MenuGrowName', '&#x1F331; ";
//~ footer += GrowName;
//~ footer += "');\n";
//~ // include the GrowName in the title
//~ footer += "document.title = 'CanGrow - ";
//~ footer += GrowName;
//~ footer += "';";
//~ footer += "</script>";
//~ }
//~ footer += FPSTR(HTMLfooter);
return header;
}
// returns footer with javascript stuff // returns footer with javascript stuff
String returnHTMLfooter(String MenuEntry = "") { String returnHTMLfooter(String MenuEntry = "") {
String footer; String footer;
@ -1418,35 +1450,36 @@ void SysWipe() {
} }
void WebAuth() {
/* /*
* TODO * TODO
* DOES NOT WORK WHEN CONNECTED TO EXISTING WIFI * DOES NOT WORK WHEN CONNECTED TO EXISTING WIFI
* IDK WHY * IDK WHY
* *
*/
char webAuthRealm[] = "CanGrowRealm"; * void WebAuth() {
if(!webserver.authenticate(WebUiUsername, WebUiPassword)) { *
String body = FPSTR(HTMLheader); * char webAuthRealm[] = "CanGrowRealm";
body += "<h1>Login failed.</h1>"; * if(!webserver.authenticate(WebUiUsername, WebUiPassword)) {
body += FPSTR(HTMLfooter); * String body = FPSTR(HTMLheader);
webserver.requestAuthentication(DIGEST_AUTH, webAuthRealm, body); * body += "<h1>Login failed.</h1>";
} * body += FPSTR(HTMLfooter);
} * webserver.requestAuthentication(DIGEST_AUTH, webAuthRealm, body);
* }
void WebAuthApi() { * }
/* *
* void WebAuthApi() {
*
* TODO * TODO
* DOES NOT WORK WHEN CONNECTED TO EXISTING WIFI * DOES NOT WORK WHEN CONNECTED TO EXISTING WIFI
* IDK WHY * IDK WHY
* *
*
* char webAuthRealm[] = "CanGrowRealm";
* if(!webserver.authenticate(WebUiUsername, WebUiPassword)) {
* webserver.requestAuthentication(DIGEST_AUTH, webAuthRealm);
* }
* }
*/ */
char webAuthRealm[] = "CanGrowRealm";
if(!webserver.authenticate(WebUiUsername, WebUiPassword)) {
webserver.requestAuthentication(DIGEST_AUTH, webAuthRealm);
}
}
/* /*
* *
@ -1454,13 +1487,6 @@ void WebAuthApi() {
* *
*/ */
// not really a webpage, but CSS is important for them :p
/*
void WEBstyleCSS() {
webserver.send(200, "text/css", HTMLstyleCSS);
}
*/
void WEB404() { void WEB404() {
String body = FPSTR(HTMLheader); String body = FPSTR(HTMLheader);
body += "<div class='warnmsg'><h1>404 - not found</h1></div>"; body += "<div class='warnmsg'><h1>404 - not found</h1></div>";
@ -2147,10 +2173,8 @@ void APIgetSensors() {
* TODO LIST / NOTES * TODO LIST / NOTES
* *
* *
* - Sunrise and Sunset PWM if PWM is set
* - avoid using javascript to set the GrowName in the Menu and the time * - avoid using javascript to set the GrowName in the Menu and the time
* as well * as well
* - rework UseLEDrelais usage
* - when PWM for fan is set, set fan speed to regulate humidity and * - when PWM for fan is set, set fan speed to regulate humidity and
* temperature * temperature
* - re-organize EEPROM saved values. * - re-organize EEPROM saved values.