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

No access to Filesystem without AMPEL_CSV

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