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

CSV_WRITER can be disabled if desired

parent 81430e88
...@@ -8,23 +8,25 @@ ...@@ -8,23 +8,25 @@
#ifndef MEASUREMENT_TIMESTEP #ifndef MEASUREMENT_TIMESTEP
# error Missing config.h file. Please copy config.example.h to config.h. # error Missing config.h file. Please copy config.example.h to config.h.
#endif #endif
#ifdef CSV_WRITER
# include "csv_writer.h"
#endif
#ifdef MQTT #ifdef MQTT
# include "mqtt.h" # include "mqtt.h"
#endif #endif
#ifdef LORAWAN #ifdef LORAWAN
# include "lorawan.h" # include "lorawan.h"
#endif #endif
#ifdef HTTP
# include "web_server.h"
#endif
#include "util.h" #include "util.h"
#include "wifi_util.h" #include "wifi_util.h"
#include "co2_sensor.h" #include "co2_sensor.h"
#ifdef HTTP
# include "web_server.h"
#endif
#include "led_effects.h" #include "led_effects.h"
#include "csv_writer.h"
#if defined(ESP8266) #if defined(ESP8266)
//allows sensor to be seen as SENSOR_ID.local, from the local network. For example : espd03cc5.local //allows sensor to be seen as SENSOR_ID.local, from the local network. For example : espd03cc5.local
......
...@@ -100,8 +100,9 @@ void setup() { ...@@ -100,8 +100,9 @@ void setup() {
#endif #endif
} }
//TODO: Add a config to deactivate CSV logging #ifdef CSV_WRITER
csv_writer::initialize(); csv_writer::initialize();
#endif
#if defined(LORAWAN) && defined(ESP32) #if defined(LORAWAN) && defined(ESP32)
lorawan::initialize(); lorawan::initialize();
......
...@@ -178,7 +178,10 @@ namespace sensor { ...@@ -178,7 +178,10 @@ namespace sensor {
logToSerial(); logToSerial();
//TODO: Move the 3 back to ampel-firmware.ino and remove headers from co2_sensor.h //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); csv_writer::logIfTimeHasCome(timestamp, co2, temperature, humidity);
#endif
#ifdef MQTT #ifdef MQTT
mqtt::publishIfTimeHasCome(timestamp, co2, temperature, humidity); mqtt::publishIfTimeHasCome(timestamp, co2, temperature, humidity);
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
// # define MQTT_SENDING_INTERVAL MEASUREMENT_TIMESTEP * 5 // [s] // # define MQTT_SENDING_INTERVAL MEASUREMENT_TIMESTEP * 5 // [s]
# define MQTT_SENDING_INTERVAL 300 // [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 ? // 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 // 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 // Set to 0 if you want to send values after each measurement
......
...@@ -57,11 +57,13 @@ namespace web_server { ...@@ -57,11 +57,13 @@ namespace web_server {
"<div class='pure-g'><div class='pure-u-1'><div class='pure-menu'><p class='pure-menu-heading'>HfT-Stuttgart CO<sub>2</sub> Ampel</p></div></div>\n" "<div class='pure-g'><div class='pure-u-1'><div class='pure-menu'><p class='pure-menu-heading'>HfT-Stuttgart CO<sub>2</sub> Ampel</p></div></div>\n"
"<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='#graph' class='pure-menu-link'>Graph</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 CSV_WRITER
"<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"
"<li class='pure-menu-item' id='led'>&#11044;</li>\n"// LED #endif
"<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.
...@@ -82,8 +84,10 @@ namespace web_server { ...@@ -82,8 +84,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 CSV_WRITER
"<tr><td>Last CSV write</td><td>%s</td></tr>\n" "<tr><td>Last CSV write</td><td>%s</td></tr>\n"
"<tr><td>CSV timestep</td><td>%5d s</td></tr>\n" "<tr><td>CSV timestep</td><td>%5d s</td></tr>\n"
#endif
#ifdef MQTT #ifdef MQTT
"<tr><td>Last MQTT publish</td><td>%s</td></tr>\n" "<tr><td>Last MQTT publish</td><td>%s</td></tr>\n"
"<tr><td>MQTT publish timestep</td><td>%5d s</td></tr>\n" "<tr><td>MQTT publish timestep</td><td>%5d s</td></tr>\n"
...@@ -103,14 +107,18 @@ namespace web_server { ...@@ -103,14 +107,18 @@ namespace web_server {
"<tr><td>Uptime</td><td>%4d h %02d min %02d s</td></tr>\n" "<tr><td>Uptime</td><td>%4d h %02d min %02d s</td></tr>\n"
"</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"
#ifdef CSV_WRITER
"<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"
"<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");
script_template = PSTR("<script>\n" script_template = PSTR(
#ifdef CSV_WRITER
"<script>\n"
"document.body.style.cursor = 'default';\n" "document.body.style.cursor = 'default';\n"
"fetch('./%s',{credentials:'include'})\n" "fetch('./%s',{credentials:'include'})\n"
// Get CSV, fill table and fill diagram // Get CSV, fill table and fill diagram
...@@ -150,13 +158,15 @@ namespace web_server { ...@@ -150,13 +158,15 @@ 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"
"</body>\n" #endif
"</html>"); "</body>\n" "</html>");
// Web-server // Web-server
http.on("/", handleWebServerRoot); http.on("/", handleWebServerRoot);
#ifdef CSV_WRITER
http.on("/" + csv_writer::filename, handleWebServerCSV); http.on("/" + csv_writer::filename, handleWebServerCSV);
http.on("/delete_csv", HTTP_POST, handleDeleteCSV); http.on("/delete_csv", HTTP_POST, handleDeleteCSV);
#endif
http.onNotFound(handlePageNotFound); http.onNotFound(handlePageNotFound);
http.begin(); http.begin();
...@@ -198,7 +208,9 @@ namespace web_server { ...@@ -198,7 +208,9 @@ namespace web_server {
// Body // Body
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 CSV_WRITER
csv_writer::last_successful_write.c_str(), config::csv_interval, csv_writer::last_successful_write.c_str(), config::csv_interval,
#endif
#ifdef MQTT #ifdef MQTT
mqtt::last_successful_publish.c_str(), config::sending_interval, mqtt::last_successful_publish.c_str(), config::sending_interval,
#endif #endif
......
Supports Markdown
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