das mit dem SPIFFS macht das ganze für mich dennoch eher komplizierter und unübersichtlicher als einfacher.
Ich kann besser mit ein paar untereinandergeschriebenen Wiederholungen für Variablen- und Buttonanzeige umgehen als mit kompliziert verschachtelten Funktionen mit -zig Parametern.
Einfacher wäre es tatsächlich, wenn ich schreiben könnte statt
Code:
float Temperaturestat=-999, Humiditystat=-999;
uint8_t led1stat=0, led2stat=0;
//----------------------------------------------------------
String SendHTML(){
String script = "<!DOCTYPE html> <html>\n";
script +="<head>";
script +="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" ;
script +="<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
script +="<title>LED Control</title>\n";
script +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
script +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
script +=".button {display: block;width: 80px;background-color: #3498db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
script +=".button-on {background-color: #3498db;}\n";
script +=".button-on:active {background-color: #2980b9;}\n";
script +=".button-off {background-color: #34495e;}\n";
script +=".button-off:active {background-color: #2c3e50;}\n";
script +="p {font-size: 20px;color: #888;margin-bottom: 10px;}\n"; // 14px;
script +="</style>\n";
script +="</head>\n";
script +="<body>\n";
script +="<h1>ESP32 Web Server</h1>\n";
// script +="<h3>Using Station(STA) Mode</h3>\n";
if(led1stat)
{script +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
else
{script +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}
if(led2stat)
{script +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";}
else
{script +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";}
script +="<h1>ESP32 Weather Report</h1>\n";
script +="<h1>";
script +="<p>Temperature: ";
script +=(int)Temperaturestat;
script +="°C</p>";
script +="<p>Humidity: ";
script +=(int)Humiditystat;
script +="%</p>";
script +="</h1>";
script +="</body>\n";
script +="</html>\n";
return script;
}
jetzt, vereinfacht:
Code:
float Temperaturestat=-999, Humiditystat=-999;
uint8_t led1stat=0, led2stat=0;
//----------------------------------------------------------
String SendHTML(){
String script = startHtmlWebsite();
script += defineFonts();
script += defineColors();
script += importWidgets();
script += printTitle(h1, "ESP32 Web Server" );
script += printText(h3, "Using Station(STA) Mode \n");
script += addButton("LED1 Status: %s \n", led1stat);
script += addButton("LED2 Status: %s \n", led2stat);
script += printText(h1, "ESP32 Weather Report \n");
script += printVar(h2, "Temperature: %d° \n ", (int)Temperaturestat );
script += printVar(h2, "Humidity: %d%% \n ", (int)Humiditystat );
script += finishHtmlWebsite();
return script;
}
Lesezeichen