Commit e7a53dfc authored by Eric Duminil's avatar Eric Duminil
Browse files

Redistributing HTML parts

parent f25fcc79
Pipeline #5879 passed with stage
in 2 minutes and 29 seconds
......@@ -52,10 +52,10 @@ namespace web_server {
"<div class='pure-u-1'><ul class='pure-menu pure-menu-horizontal pure-menu-list'>"
"<li class='pure-menu-item'><a href='/config' class='pure-menu-link'>Config</a></li>"
"<li class='pure-menu-item'><a href='#table' class='pure-menu-link'>Info</a></li>"
"<li class='pure-menu-item'><a href='#graph' class='pure-menu-link'>Graph</a></li>");
"<li class='pure-menu-item'><a href='#graph' class='pure-menu-link'>Graph</a></li>"
"<li class='pure-menu-item'><a href='#log' class='pure-menu-link'>Log</a></li>");
body1_template = PSTR("<li class='pure-menu-item'><a href='#log' class='pure-menu-link'>Log</a></li>"
"<li class='pure-menu-item'><a href='%s' class='pure-menu-link'>Download CSV</a></li>"
body1_template = PSTR("<li class='pure-menu-item'><a href='%s' class='pure-menu-link'>Download CSV</a></li>"
"<li class='pure-menu-item' id='led'>&#11044;</li>" // LED
"</ul></div></div>"
"<script>"
......@@ -85,43 +85,44 @@ namespace web_server {
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Last publish</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>");
"</tbody>"
#if defined(ESP32)
"<tbody %s>"
"<tr><th colspan='2'>LoRaWAN</th></tr>"
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Frequency</td><td>%s MHz</td></tr>"
"<tr><td>Last transmission</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>"
#endif
);
body2_template =
PSTR(
#if defined(ESP32)
"<tbody %s>"
"<tr><th colspan='2'>LoRaWAN</th></tr>"
"<tr><td>Connected?</td><td>%s</td></tr>"
"<tr><td>Frequency</td><td>%s MHz</td></tr>"
"<tr><td>Last transmission</td><td>%s</td></tr>"
"<tr><td>Interval</td><td>%5d s</td></tr>"
"</tbody>"
#endif
"<tr><th colspan='2'>Sensor</th></tr>"
"<tr><td>Temperature offset</td><td>%.1fK</td></tr>"
"<tr><td>Auto-calibration?</td><td>%s</td></tr>"
"<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>"
"<tr><td>Local IP</td><td><a href='http://%s'>%s</a></td></tr>"
"<tr><td>MAC</td><td>%s</td></tr>"
"<tr><td>Free heap space</td><td>%6d bytes</td></tr>"
"<tr><td>Largest heap block</td><td>%6d bytes</td></tr>"
"<tr><td>Frag</td><td>%3d%%</td></tr>"
"<tr><td>Max loop duration</td><td>%5d ms</td></tr>"
"<tr><td>Board</td><td>%s</td></tr>"
"<tr><td>ID</td><td>%s</td></tr>"
"<tr><td>Ampel firmware</td><td>%s</td></tr>"
"<tr><td>Uptime</td><td>%2d d %4d h %02d min %02d s</td></tr>"
"</table>"
"<div id='log' class='pure-u-1 pure-u-md-1-2'></div>"
"<form action='/command'><input type='text' id='send' name='send'><input type='submit' value='Send'></form>"
"<form action='/delete_csv' method='POST' onsubmit=\"return confirm('Are you really sure you want to delete all data?') && (document.body.style.cursor = 'wait');\">"
"<input type='submit' value='Delete CSV'/>"
"</form>"
"<button onclick=\"fetch('/command?send=set_time '+Math.floor(Date.now()/1000))\" %s>Set time!</button>" // Can be useful in AP mode
"</div>"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-firmware' target='_blank'>Source code</a>&nbsp;"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-documentation' target='_blank'>Documentation</a>");
"<tr><td>Temperature offset</td><td>%.1fK</td></tr>"
"<tr><td>Auto-calibration?</td><td>%s</td></tr>"
"<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>"
"<tr><td>Local IP</td><td><a href='http://%s'>%s</a></td></tr>"
"<tr><td>MAC</td><td>%s</td></tr>"
"<tr><td>Free heap space</td><td>%6d bytes</td></tr>"
"<tr><td>Largest heap block</td><td>%6d bytes</td></tr>"
"<tr><td>Frag</td><td>%3d%%</td></tr>"
"<tr><td>Max loop duration</td><td>%5d ms</td></tr>"
"<tr><td>Board</td><td>%s</td></tr>"
"<tr><td>ID</td><td>%s</td></tr>"
"<tr><td>Ampel firmware</td><td>%s</td></tr>"
"<tr><td>Uptime</td><td>%2d d %4d h %02d min %02d s</td></tr>"
"</table>"
"<div id='log' class='pure-u-1 pure-u-md-1-2'></div>"
"<form action='/command'><input type='text' id='send' name='send'><input type='submit' value='Send'></form>"
"<form action='/delete_csv' method='POST' onsubmit=\"return confirm('Are you really sure you want to delete all data?') && (document.body.style.cursor = 'wait');\">"
"<input type='submit' value='Delete CSV'/>"
"</form>"
"<button onclick=\"fetch('/command?send=set_time '+Math.floor(Date.now()/1000))\" %s>Set time!</button>" // Can be useful in AP mode
"</div>"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-firmware' target='_blank'>Source code</a>&nbsp;"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-documentation' target='_blank'>Documentation</a>");
script_template = PSTR("<script>"
"document.body.style.cursor = 'default';"
......@@ -201,9 +202,9 @@ namespace web_server {
ss -= mm * 60;
//NOTE: Splitting in multiple parts in order to use less RAM. Higher than 2000 apparently crashes the ESP8266
char content[1700];
char content[1600];
// Current size (with Lorawan, timesteps and long thing name):
// INFO - Header size : 1269 - Body1 size : 1259 - Body2 size : 1620 - Script size : 1496
// INFO - Header size : 1347 - Body1 size : 1448 - Body2 size : 1475 - Script size : 1507
snprintf_P(content, sizeof(content), header_template, sensor::co2, config::ampel_name(), wifi::local_ip);
......@@ -217,21 +218,22 @@ namespace web_server {
sensor::temperature, sensor::humidity, sensor::timestamp, config::measurement_timestep,
config::is_csv_active() ? "" : "hidden", csv_writer::last_successful_write, config::csv_interval,
csv_writer::getAvailableSpace() / 1024, config::is_mqtt_active() ? "" : "hidden",
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval);
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval
#if defined(ESP32)
, config::is_lorawan_active() ? "" : "hidden", lorawan::connected ? "Yes" : "No",
config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval
#endif
);
Serial.print(F(" - Body1 size : "));
Serial.print(strlen(content));
web_config::http.sendContent(content);
snprintf_P(content, sizeof(content), body2_template,
#if defined(ESP32)
config::is_lorawan_active() ? "" : "hidden", lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan,
lorawan::last_transmission, config::lorawan_sending_interval,
#endif
config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", config::ampel_name(),
config::ampel_name(), wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(),
esp_get_max_free_block_size(), esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board,
ampel.sensorId, ampel.version, dd, hh, mm, ss, wifi::isAccessPoint() ? "" : "hidden");
snprintf_P(content, sizeof(content), body2_template, config::temperature_offset,
config::auto_calibrate_sensor ? "Yes" : "No", config::ampel_name(), config::ampel_name(), wifi::local_ip,
wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), esp_get_max_free_block_size(),
esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board, ampel.sensorId, ampel.version, dd, hh, mm,
ss, wifi::isAccessPoint() ? "" : "hidden");
Serial.print(F(" - Body2 size : "));
Serial.print(strlen(content));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment