Commit 40c139a8 authored by Eric Duminil's avatar Eric Duminil
Browse files

Always initialize filesystem, but csv can be off

parent b9002c70
Pipeline #5773 passed with stage
in 2 minutes and 8 seconds
...@@ -111,9 +111,7 @@ void setup() { ...@@ -111,9 +111,7 @@ void setup() {
sensor::initialize(); sensor::initialize();
#ifdef AMPEL_CSV
csv_writer::initialize(ampel.sensorId); csv_writer::initialize(ampel.sensorId);
#endif
#ifdef AMPEL_WIFI // Structure doesn't make sense anymore #ifdef AMPEL_WIFI // Structure doesn't make sense anymore
wifi::defineCommands(); wifi::defineCommands();
...@@ -161,10 +159,10 @@ void loop() { ...@@ -161,10 +159,10 @@ void loop() {
checkSerialInput(); checkSerialInput();
if (sensor::processData()) { if (sensor::processData()) {
#ifdef AMPEL_CSV if (config::csv_active()) {
//TODO: Check if not in AP mode. Lines get written with 1970 otherwise. //TODO: Check if not in AP mode. Lines get written with 1970 otherwise.
csv_writer::logIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity); csv_writer::logIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity);
#endif }
#if defined(AMPEL_WIFI) #if defined(AMPEL_WIFI)
if (config::mqtt_active()) { if (config::mqtt_active()) {
......
...@@ -292,9 +292,12 @@ namespace config { ...@@ -292,9 +292,12 @@ namespace config {
bool &daylight_saving_time = web_config::dstParam.value(); bool &daylight_saving_time = web_config::dstParam.value();
// CSV // CSV
bool csv_active() {
return web_config::csvParams.isActive();
}
uint16_t &csv_interval = web_config::csvTimestepParam.value(); uint16_t &csv_interval = web_config::csvTimestepParam.value();
// MQTT // MQTT
bool mqtt_active() { bool mqtt_active() {
return web_config::mqttParams.isActive(); return web_config::mqttParams.isActive();
} }
......
...@@ -28,7 +28,7 @@ namespace config { ...@@ -28,7 +28,7 @@ namespace config {
extern bool &daylight_saving_time; // [true / false] extern bool &daylight_saving_time; // [true / false]
//CSV //CSV
//TODO: Add use_csv bool csv_active();
extern uint16_t &csv_interval; // [s] extern uint16_t &csv_interval; // [s]
// MQTT // MQTT
......
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
#include "wifi_util.h" #include "wifi_util.h"
#include "co2_sensor.h" #include "co2_sensor.h"
#include "sensor_console.h" #include "sensor_console.h"
#ifdef AMPEL_CSV #include "csv_writer.h"
# include "csv_writer.h"
#endif
#include "mqtt.h" #include "mqtt.h"
#ifdef AMPEL_LORAWAN #ifdef AMPEL_LORAWAN
# include "lorawan.h" # include "lorawan.h"
...@@ -50,10 +48,8 @@ namespace web_server { ...@@ -50,10 +48,8 @@ namespace web_server {
void handlePageNotFound(); void handlePageNotFound();
void handleWebServerCommand(); void handleWebServerCommand();
#ifdef AMPEL_CSV
void handleDeleteCSV(); void handleDeleteCSV();
void handleWebServerCSV(); void handleWebServerCSV();
#endif
void definePages() { void definePages() {
header_template = header_template =
...@@ -79,12 +75,10 @@ namespace web_server { ...@@ -79,12 +75,10 @@ namespace web_server {
"<div class='pure-u-1'><ul class='pure-menu pure-menu-horizontal pure-menu-list'>\n" "<div class='pure-u-1'><ul class='pure-menu pure-menu-horizontal pure-menu-list'>\n"
"<li class='pure-menu-item'><a href='/config' class='pure-menu-link'>Config</a></li>\n" "<li class='pure-menu-item'><a href='/config' class='pure-menu-link'>Config</a></li>\n"
"<li class='pure-menu-item'><a href='#table' class='pure-menu-link'>Info</a></li>\n" "<li class='pure-menu-item'><a href='#table' class='pure-menu-link'>Info</a></li>\n"
#ifdef AMPEL_CSV
"<li class='pure-menu-item'><a href='#graph' class='pure-menu-link'>Graph</a></li>\n" "<li class='pure-menu-item'><a href='#graph' class='pure-menu-link'>Graph</a></li>\n"
"<li class='pure-menu-item'><a href='#log' class='pure-menu-link'>Log</a></li>\n" "<li class='pure-menu-item'><a href='#log' class='pure-menu-link'>Log</a></li>\n"
"<li class='pure-menu-item'><a href='%s' class='pure-menu-link'>Download CSV</a></li>\n" "<li class='pure-menu-item'><a href='%s' class='pure-menu-link'>Download CSV</a></li>\n"
#endif "<li class='pure-menu-item' id='led'>&#11044;</li>\n"// LED
"<li class='pure-menu-item' id='led'>&#11044;</li>\n" // LED
"</ul></div></div>\n" "</ul></div></div>\n"
"<script>\n" "<script>\n"
// Show a colored dot on the webpage, with a similar color than on LED Ring. // Show a colored dot on the webpage, with a similar color than on LED Ring.
...@@ -104,12 +98,10 @@ namespace web_server { ...@@ -104,12 +98,10 @@ namespace web_server {
"<tr><td>Humidity</td><td>%.1f%%</td></tr>\n" "<tr><td>Humidity</td><td>%.1f%%</td></tr>\n"
"<tr><td>Last measurement</td><td>%s</td></tr>\n" "<tr><td>Last measurement</td><td>%s</td></tr>\n"
"<tr><td>Measurement timestep</td><td>%5d s</td></tr>\n" "<tr><td>Measurement timestep</td><td>%5d s</td></tr>\n"
#ifdef AMPEL_CSV
"<tr><th colspan='2'>CSV</th></tr>\n" "<tr><th colspan='2'>CSV</th></tr>\n"
"<tr><td>Last write</td><td>%s</td></tr>\n" "<tr><td>Last write</td><td>%s</td></tr>\n"
"<tr><td>Timestep</td><td>%5d s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n"
"<tr><td>Available drive space</td><td>%d kB</td></tr>\n" "<tr><td>Available drive space</td><td>%d kB</td></tr>\n"
#endif
"<tr><th colspan='2'>MQTT</th></tr>\n" "<tr><th colspan='2'>MQTT</th></tr>\n"
"<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Connected?</td><td>%s</td></tr>\n"
"<tr><td>Last publish</td><td>%s</td></tr>\n" "<tr><td>Last publish</td><td>%s</td></tr>\n"
...@@ -137,18 +129,15 @@ namespace web_server { ...@@ -137,18 +129,15 @@ namespace web_server {
"</table>\n" "</table>\n"
"<div id='log' class='pure-u-1 pure-u-md-1-2'></div>\n" "<div id='log' class='pure-u-1 pure-u-md-1-2'></div>\n"
"<form action='/command'><input type='text' id='send' name='send'><input type='submit' value='Send'></form>\n" "<form action='/command'><input type='text' id='send' name='send'><input type='submit' value='Send'></form>\n"
#ifdef AMPEL_CSV
"<form action='/delete_csv' method='POST' onsubmit=\"return confirm('Are you really sure you want to delete all data?') && (document.body.style.cursor = 'wait');\">" "<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'/>" "<input type='submit' value='Delete CSV'/>"
"</form>\n" "</form>\n"
#endif
"</div>\n"); "</div>\n");
script_template = script_template =
PSTR( PSTR(
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-firmware' target='_blank'>Source code</a>\n" "<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-firmware' target='_blank'>Source code</a>\n"
"<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-documentation' target='_blank'>Documentation</a>\n" "<a href='https://transfer.hft-stuttgart.de/gitlab/co2ampel/ampel-documentation' target='_blank'>Documentation</a>\n"
#ifdef AMPEL_CSV
"<script>\n" "<script>\n"
"document.body.style.cursor = 'default';\n" "document.body.style.cursor = 'default';\n"
"fetch('%s',{credentials:'include'})\n" "fetch('%s',{credentials:'include'})\n"
...@@ -188,17 +177,14 @@ namespace web_server { ...@@ -188,17 +177,14 @@ namespace web_server {
"return table;}\n" "return table;}\n"
"function addLogTableToPage(table){document.getElementById('log').appendChild(table);}\n" "function addLogTableToPage(table){document.getElementById('log').appendChild(table);}\n"
"</script>\n" "</script>\n"
#endif
"</body>\n" "</body>\n"
"</html>"); "</html>");
// Web-server // Web-server
web_config::http.on("/", handleWebServerRoot); web_config::http.on("/", handleWebServerRoot);
web_config::http.on("/command", handleWebServerCommand); web_config::http.on("/command", handleWebServerCommand);
#ifdef AMPEL_CSV web_config::http.on(csv_writer::filename, handleWebServerCSV);
web_config::http.on(csv_writer::filename, handleWebServerCSV); //NOTE: csv_writer should have been initialized first.
web_config::http.on("/delete_csv", HTTP_POST, handleDeleteCSV); web_config::http.on("/delete_csv", HTTP_POST, handleDeleteCSV);
#endif
} }
// Allow access if http_user or http_password are empty, or if provided credentials match // Allow access if http_user or http_password are empty, or if provided credentials match
...@@ -228,11 +214,8 @@ namespace web_server { ...@@ -228,11 +214,8 @@ namespace web_server {
char content[2000]; // Update if needed char content[2000]; // Update if needed
// INFO - Header size : 1767 - Body size : 1991 - Script size : 1909 // INFO - Header size : 1767 - Body size : 1991 - Script size : 1909
snprintf_P(content, sizeof(content), header_template, sensor::co2, ampel.sensorId, wifi::local_ip snprintf_P(content, sizeof(content), header_template, sensor::co2, ampel.sensorId, wifi::local_ip,
#ifdef AMPEL_CSV csv_writer::filename);
, csv_writer::filename
#endif
);
// Serial.print(F("INFO - Header size : ")); // Serial.print(F("INFO - Header size : "));
// Serial.print(strlen(content)); // Serial.print(strlen(content));
...@@ -241,11 +224,9 @@ namespace web_server { ...@@ -241,11 +224,9 @@ namespace web_server {
// Body // Body
snprintf_P(content, sizeof(content), body_template, ampel.sensorId, sensor::co2, sensor::temperature, snprintf_P(content, sizeof(content), body_template, ampel.sensorId, sensor::co2, sensor::temperature,
sensor::humidity, sensor::timestamp, config::measurement_timestep, sensor::humidity, sensor::timestamp, config::measurement_timestep, csv_writer::last_successful_write,
#ifdef AMPEL_CSV config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No",
csv_writer::last_successful_write, config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::last_successful_publish, config::mqtt_sending_interval,
#endif
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval,
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission,
config::lorawan_sending_interval, config::lorawan_sending_interval,
...@@ -259,18 +240,13 @@ namespace web_server { ...@@ -259,18 +240,13 @@ namespace web_server {
web_config::http.sendContent(content); web_config::http.sendContent(content);
// Script // Script
snprintf_P(content, sizeof(content), script_template snprintf_P(content, sizeof(content), script_template, csv_writer::filename, ampel.sensorId);
#ifdef AMPEL_CSV
, csv_writer::filename, ampel.sensorId
#endif
);
// Serial.print(F(" - Script size : ")); // Serial.print(F(" - Script size : "));
// Serial.println(strlen(content)); // Serial.println(strlen(content));
web_config::http.sendContent(content); web_config::http.sendContent(content);
} }
#ifdef AMPEL_CSV
void handleWebServerCSV() { void handleWebServerCSV() {
if (!shouldBeAllowed()) { if (!shouldBeAllowed()) {
return web_config::http.requestAuthentication(DIGEST_AUTH); return web_config::http.requestAuthentication(DIGEST_AUTH);
...@@ -297,7 +273,6 @@ namespace web_server { ...@@ -297,7 +273,6 @@ namespace web_server {
web_config::http.sendHeader("Location", "/"); web_config::http.sendHeader("Location", "/");
web_config::http.send(303); web_config::http.send(303);
} }
#endif
void handleWebServerCommand() { void handleWebServerCommand() {
if (!shouldBeAllowed()) { if (!shouldBeAllowed()) {
......
Markdown is supported
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