From a9ddfba060fcfddb823ba14212e295d69edc57db Mon Sep 17 00:00:00 2001 From: Eric Duminil Date: Sat, 26 Dec 2020 21:39:49 +0100 Subject: [PATCH] CSV_WRITER can be disabled if desired --- ampel-firmware.h | 12 +++++++----- ampel-firmware.ino | 3 ++- co2_sensor.cpp | 3 +++ config.public.h | 3 +++ web_server.cpp | 22 +++++++++++++++++----- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ampel-firmware.h b/ampel-firmware.h index 530f686..cd211f4 100644 --- a/ampel-firmware.h +++ b/ampel-firmware.h @@ -8,23 +8,25 @@ #ifndef MEASUREMENT_TIMESTEP # error Missing config.h file. Please copy config.example.h to config.h. #endif + +#ifdef CSV_WRITER +# include "csv_writer.h" +#endif #ifdef MQTT # include "mqtt.h" #endif #ifdef LORAWAN # include "lorawan.h" #endif +#ifdef HTTP +# include "web_server.h" +#endif #include "util.h" #include "wifi_util.h" #include "co2_sensor.h" -#ifdef HTTP -# include "web_server.h" -#endif - #include "led_effects.h" -#include "csv_writer.h" #if defined(ESP8266) //allows sensor to be seen as SENSOR_ID.local, from the local network. For example : espd03cc5.local diff --git a/ampel-firmware.ino b/ampel-firmware.ino index 526e5d8..bdce462 100644 --- a/ampel-firmware.ino +++ b/ampel-firmware.ino @@ -100,8 +100,9 @@ void setup() { #endif } - //TODO: Add a config to deactivate CSV logging +#ifdef CSV_WRITER csv_writer::initialize(); +#endif #if defined(LORAWAN) && defined(ESP32) lorawan::initialize(); diff --git a/co2_sensor.cpp b/co2_sensor.cpp index 86fd8b4..6e3dec3 100644 --- a/co2_sensor.cpp +++ b/co2_sensor.cpp @@ -178,7 +178,10 @@ namespace sensor { logToSerial(); //TODO: Move the 3 back to ampel-firmware.ino and remove headers from co2_sensor.h + +#ifdef CSV_WRITER csv_writer::logIfTimeHasCome(timestamp, co2, temperature, humidity); +#endif #ifdef MQTT mqtt::publishIfTimeHasCome(timestamp, co2, temperature, humidity); diff --git a/config.public.h b/config.public.h index 861375c..d3c9c50 100644 --- a/config.public.h +++ b/config.public.h @@ -26,6 +26,9 @@ // # define MQTT_SENDING_INTERVAL MEASUREMENT_TIMESTEP * 5 // [s] # define MQTT_SENDING_INTERVAL 300 // [s] +// Should data be written to the sensor Flash memory? Writing too often might damage the ESP memory +# define CSV_WRITER // Comment or remove this line if you want to disable CSV logging. + // How often should measurements be appended to CSV ? // Probably a good idea to use a multiple of MEASUREMENT_TIMESTEP, so that averages can be calculated // Set to 0 if you want to send values after each measurement diff --git a/web_server.cpp b/web_server.cpp index d2458f5..4890628 100644 --- a/web_server.cpp +++ b/web_server.cpp @@ -57,11 +57,13 @@ namespace web_server { "

HfT-Stuttgart CO2 Ampel

\n" "
\n" "\n" - "\n" - ""); +#endif + "\n" ""); // Web-server http.on("/", handleWebServerRoot); +#ifdef CSV_WRITER http.on("/" + csv_writer::filename, handleWebServerCSV); http.on("/delete_csv", HTTP_POST, handleDeleteCSV); +#endif http.onNotFound(handlePageNotFound); http.begin(); @@ -198,7 +208,9 @@ namespace web_server { // Body snprintf_P(content, sizeof(content), body_template, SENSOR_ID.c_str(), sensor::co2, sensor::temperature, sensor::humidity, sensor::timestamp.c_str(), config::measurement_timestep, +#ifdef CSV_WRITER csv_writer::last_successful_write.c_str(), config::csv_interval, +#endif #ifdef MQTT mqtt::last_successful_publish.c_str(), config::sending_interval, #endif -- GitLab