Non working version with replace functions
This commit is contained in:
parent
3cbdf20e79
commit
55821b8282
5 changed files with 147 additions and 129 deletions
|
@ -1,8 +1,7 @@
|
|||
|
||||
String getConfigHTML()
|
||||
{
|
||||
String config_html = ""
|
||||
"<form class=\"pure-form pure-form-aligned\" action=\"/\" method=\"post\">"
|
||||
String config_html = "<form class=\"pure-form pure-form-aligned\" action=\"/\" method=\"post\">"
|
||||
"<h3>Config</h3>"
|
||||
"<div class=\"pure-control-group\">"
|
||||
"<label for=\"startup\">"
|
||||
|
|
|
@ -618,8 +618,30 @@ void init_webserver()
|
|||
ESP.reset();
|
||||
}
|
||||
|
||||
// Generate HTML page
|
||||
String http_content = getIndexHTML();
|
||||
// ***** Generate HTML page ***** //
|
||||
|
||||
server.sendHeader("Content-Type", "text/html");
|
||||
server.sendHeader("Connection", "close");
|
||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||
server.send(200);
|
||||
server.sendContent(replacePlaceholder(replaceLightsControl(getIndexHTMLTop())));
|
||||
server.sendContent(replacePlaceholder(getConfigHTML()));
|
||||
server.sendContent(replacePlaceholder(getIndexHTMLBottom()));
|
||||
});
|
||||
|
||||
server.on("/reset", []()
|
||||
{ // trigger manual reset
|
||||
server.send(200, "text/html", "reset");
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
});
|
||||
|
||||
server.onNotFound(handleNotFound);
|
||||
}
|
||||
|
||||
String replacePlaceholder(String in)
|
||||
{
|
||||
String http_content = in;
|
||||
|
||||
http_content.replace("{{LIGHT_NAME}}", (String)light_name);
|
||||
|
||||
|
@ -641,24 +663,6 @@ void init_webserver()
|
|||
|
||||
http_content.replace("{{TRANSITION_TIME}}", (String)default_transitiontime);
|
||||
|
||||
String light_content = "";
|
||||
// Light control
|
||||
for (uint8 light_num = 0; light_num < LIGHTS_COUNT; light_num++)
|
||||
{
|
||||
// Generate lights part of the HTML page
|
||||
String tmp_light_content = getLightControlHTML();
|
||||
|
||||
// on/off buttons and slider
|
||||
tmp_light_content.replace("{{LIGHT_NUMBER}}", (String)(light_num + 1));
|
||||
tmp_light_content.replace("{{LIGHT_NUMBER_DEC}}", (String)light_num);
|
||||
|
||||
// add the lights code to the html output string
|
||||
light_content += tmp_light_content;
|
||||
}
|
||||
|
||||
// add the created lights control code to the html output
|
||||
http_content.replace("{{LIGHTS_CONTROL}}", light_content);
|
||||
|
||||
int ls_val = EEPROM.read(EEPROM_LAST_STATE_STARTUP_ADDRESS);
|
||||
if (ls_val == LAST_STATE_STARTUP_LIGHT_LAST_STATE)
|
||||
{
|
||||
|
@ -733,15 +737,28 @@ void init_webserver()
|
|||
http_content.replace("{{PWM_MIN}}", (String)PWM_MIN);
|
||||
http_content.replace("{{PWM_MAX}}", (String)PWM_MAX);
|
||||
|
||||
server.send(200, "text/html", http_content);
|
||||
});
|
||||
|
||||
server.on("/reset", []()
|
||||
{ // trigger manual reset
|
||||
server.send(200, "text/html", "reset");
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
});
|
||||
|
||||
server.onNotFound(handleNotFound);
|
||||
return http_content;
|
||||
}
|
||||
|
||||
String replaceLightsControl(String in)
|
||||
{
|
||||
String light_content = "";
|
||||
// Light control
|
||||
for (uint8 light_num = 0; light_num < LIGHTS_COUNT; light_num++)
|
||||
{
|
||||
// Generate lights part of the HTML page
|
||||
String tmp_light_content = getLightControlHTML();
|
||||
|
||||
// on/off buttons and slider
|
||||
tmp_light_content.replace("{{LIGHT_NUMBER}}", (String)(light_num + 1));
|
||||
tmp_light_content.replace("{{LIGHT_NUMBER_DEC}}", (String)light_num);
|
||||
|
||||
// add the lights code to the html output string
|
||||
light_content += tmp_light_content;
|
||||
}
|
||||
|
||||
// add the created lights control code to the html output
|
||||
in.replace("{{LIGHTS_CONTROL}}", light_content);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
|
||||
String getIndexHTML()
|
||||
|
||||
String getIndexHTMLTop()
|
||||
{
|
||||
String index_html = ""
|
||||
"<!doctype html>"
|
||||
String index_html = "<!doctype html>"
|
||||
"<html>"
|
||||
"<head>"
|
||||
"<style></style>"
|
||||
"<meta charset=\"utf-8\">"
|
||||
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
|
||||
"<title>Light setup</title>"
|
||||
"<title>Light setup - {{LIGHT_NAME}}</title>"
|
||||
"<script src=\"https://code.jquery.com/jquery-3.6.0.min.js\"></script>"
|
||||
"<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>"
|
||||
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js\"></script>"
|
||||
|
@ -99,9 +99,13 @@ String getIndexHTML()
|
|||
"<div id=\"plot_chart\"></div>"
|
||||
"</td>"
|
||||
"</tr>"
|
||||
"</table>"
|
||||
"{{CONFIG_PAGE}}"
|
||||
"<script>"
|
||||
"</table>";
|
||||
return index_html;
|
||||
}
|
||||
|
||||
String getIndexHTMLBottom()
|
||||
{
|
||||
const char index_html[] = "<script>"
|
||||
"function loadGraphData() {"
|
||||
"console.log('----> generate graph <----');"
|
||||
"$.getJSON('/tc_data_blocks', function(data) {"
|
||||
|
@ -275,5 +279,5 @@ String getIndexHTML()
|
|||
"</fieldset>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
return index_html;
|
||||
return String(index_html);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<style></style>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Light setup</title>
|
||||
<title>Light setup - {{LIGHT_NAME}}</title>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
|
||||
|
@ -90,7 +90,6 @@
|
|||
<tr>
|
||||
<td>
|
||||
{{LIGHTS_CONTROL}}
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<div id="plot_chart"></div>
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
String getLightControlHTML()
|
||||
{
|
||||
String light_control_html = ""
|
||||
"<h4>Light {{LIGHT_NUMBER}}</h4>"
|
||||
String light_control_html = "<h4>Light {{LIGHT_NUMBER}}</h4>"
|
||||
"<div class=\"pure-control-group\">"
|
||||
"<label for=\"power\">"
|
||||
"<strong>Power</strong>"
|
||||
|
|
Loading…
Reference in a new issue