diff --git a/mqtt.cpp b/mqtt.cpp index e7e6e33f12bb6f21cbccbb1fa52566ef5b4d1782..98eefc83683981c37158a7b42b3840d077e47675 100644 --- a/mqtt.cpp +++ b/mqtt.cpp @@ -77,6 +77,7 @@ namespace mqtt { LedEffects::showKITTWheel(color::green, 1); } +#ifdef AMPEL_CSV void setCSVinterval(String messageString) { messageString.replace("csv ", ""); config::csv_interval = messageString.toInt(); @@ -85,6 +86,7 @@ namespace mqtt { Serial.println("s."); LedEffects::showKITTWheel(color::green, 1); } +#endif void calibrateSensorToSpecificPPM(String messageString) { messageString.replace("calibrate ", ""); @@ -149,14 +151,16 @@ namespace mqtt { calibrateSensorToSpecificPPM(messageString); } else if (messageString.startsWith("mqtt ")) { setMQTTinterval(messageString); - } else if (messageString.startsWith("csv ")) { - setCSVinterval(messageString); } else if (messageString == "publish") { Serial.println(F("Forcing MQTT publish now.")); publish(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity); +#ifdef AMPEL_CSV + } else if (messageString.startsWith("csv ")) { + setCSVinterval(messageString); } else if (messageString == "format_filesystem") { FS_LIB.format(); LedEffects::showKITTWheel(color::blue, 2); +#endif } else if (messageString == "night_mode") { LedEffects::toggleNightMode(); } else if (messageString == "local_ip") { diff --git a/mqtt.h b/mqtt.h index 9af46c8e60eb19650635244a7cd8ab09545b9cc1..8b520cc9459c2ec0fc4f7aa4cf9a45cee28c7067 100644 --- a/mqtt.h +++ b/mqtt.h @@ -4,7 +4,9 @@ #include <Arduino.h> #include "config.h" #include "led_effects.h" -#include "csv_writer.h" +#ifdef AMPEL_CSV +# include "csv_writer.h" +#endif #include "co2_sensor.h" #include "src/lib/PubSubClient/src/PubSubClient.h" #include "wifi_util.h" diff --git a/util.cpp b/util.cpp index cd7c53bd1423d8ae3056711b9474f4cb1f65c823..c32a5c561d717539d8ff0809724d381461131deb 100644 --- a/util.cpp +++ b/util.cpp @@ -39,8 +39,10 @@ namespace ntp { } void resetAmpel() { - Serial.print("Resetting"); + Serial.print(F("Resetting")); +#ifdef AMPEL_CSV FS_LIB.end(); +#endif LedEffects::LEDsOff(); delay(1000); ESP.restart(); diff --git a/util.h b/util.h index 5a46bd13eaf27d06b3aeae7a67f8f05038ef0ae5..c9a8a943aaf0af03dc933e171070c56eb7a93eab 100644 --- a/util.h +++ b/util.h @@ -3,8 +3,9 @@ #include <Arduino.h> #include "config.h" #include "wifi_util.h" // To get MAC -//FIXME: Only if CSV -#include "csv_writer.h" // To close filesystem before reset +#ifdef AMPEL_CSV +# include "csv_writer.h" // To close filesystem before reset +#endif #include <WiFiUdp.h> //required for NTP #include "src/lib/NTPClient-master/NTPClient.h" // NTP diff --git a/web_server.cpp b/web_server.cpp index c96b2f44b96a09b7e389e21f37b0d14da3771a2b..ae2ad1f619e85b00a3db3e3afb87203bb08a936a 100644 --- a/web_server.cpp +++ b/web_server.cpp @@ -21,9 +21,12 @@ namespace web_server { const char *body_template; const char *script_template; void handleWebServerRoot(); - void handleWebServerCSV(); void handlePageNotFound(); + +#ifdef AMPEL_CSV void handleDeleteCSV(); + void handleWebServerCSV(); +#endif #if defined(ESP8266) ESP8266WebServer http(80); // Create a webserver object that listens for HTTP request on port 80 @@ -198,8 +201,6 @@ namespace web_server { ss -= hh * 3600; uint8_t mm = ss / 60; ss -= mm * 60; - //FIXME: only if AMPEL_CSV - uint16_t available_fs_space = csv_writer::getAvailableSpace() / 1024; //NOTE: Splitting in multiple parts in order to use less RAM char content[2000]; // Update if needed @@ -207,7 +208,11 @@ namespace web_server { // Header snprintf_P(content, sizeof(content), header_template, sensor::co2, SENSOR_ID.c_str(), - WiFi.localIP().toString().c_str(), csv_writer::filename.c_str()); + WiFi.localIP().toString().c_str() +#ifdef AMPEL_CSV + , csv_writer::filename.c_str() +#endif + ); http.setContentLength(CONTENT_LENGTH_UNKNOWN); http.send_P(200, PSTR("text/html"), content); @@ -216,7 +221,7 @@ namespace web_server { 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 AMPEL_CSV - csv_writer::last_successful_write.c_str(), config::csv_interval, available_fs_space, + csv_writer::last_successful_write.c_str(), config::csv_interval, csv_writer::getAvailableSpace() / 1024, #endif #ifdef AMPEL_MQTT mqtt::last_successful_publish.c_str(), config::sending_interval, @@ -231,11 +236,16 @@ namespace web_server { http.sendContent(content); // Script - snprintf_P(content, sizeof(content), script_template, csv_writer::filename.c_str(), SENSOR_ID.c_str()); + snprintf_P(content, sizeof(content), script_template +#ifdef AMPEL_CSV + , csv_writer::filename.c_str(), SENSOR_ID.c_str() +#endif + ); http.sendContent(content); } +#ifdef AMPEL_CSV void handleWebServerCSV() { if (!shouldBeAllowed()) { return http.requestAuthentication(DIGEST_AUTH); @@ -260,6 +270,7 @@ namespace web_server { http.sendHeader("Location", "/"); http.send(303); } +#endif void handlePageNotFound() { http.send(404, F("text/plain"), F("404: Not found"));