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 {
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") {
......
......@@ -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"
......
......@@ -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();
......
......@@ -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
......
......@@ -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"));
......
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