Commit 9c11a3cb authored by Eric Duminil's avatar Eric Duminil
Browse files

CSV interval as first config.

parent 6625ade7
#include "csv_writer.h" #include "csv_writer.h"
#include "config.h" #include "config.h"
#include "web_config.h"
#include "ntp.h" #include "ntp.h"
#include "led_effects.h" #include "led_effects.h"
#include "sensor_console.h" #include "sensor_console.h"
namespace config {
// Values should be defined in config.h
uint16_t csv_interval = CSV_INTERVAL; // [s]
}
namespace csv_writer { namespace csv_writer {
unsigned long last_written_at = 0; unsigned long last_written_at = 0;
char last_successful_write[23]; char last_successful_write[23];
...@@ -166,7 +163,7 @@ namespace csv_writer { ...@@ -166,7 +163,7 @@ namespace csv_writer {
void logIfTimeHasCome(const char *timeStamp, const int16_t &co2, const float &temperature, const float &humidity) { void logIfTimeHasCome(const char *timeStamp, const int16_t &co2, const float &temperature, const float &humidity) {
unsigned long now = seconds(); unsigned long now = seconds();
if (now - last_written_at > config::csv_interval) { if (now - last_written_at > *config::csv_interval) {
last_written_at = now; last_written_at = now;
log(timeStamp, co2, temperature, humidity); log(timeStamp, co2, temperature, humidity);
} }
...@@ -176,9 +173,9 @@ namespace csv_writer { ...@@ -176,9 +173,9 @@ namespace csv_writer {
* Callbacks for sensor commands * * Callbacks for sensor commands *
*****************************************************************/ *****************************************************************/
void setCSVinterval(int32_t csv_interval) { void setCSVinterval(int32_t csv_interval) {
config::csv_interval = csv_interval; *config::csv_interval = csv_interval;
Serial.print(F("Setting CSV Interval to : ")); Serial.print(F("Setting CSV Interval to : "));
Serial.print(config::csv_interval); Serial.print(*config::csv_interval);
Serial.println("s."); Serial.println("s.");
led_effects::showKITTWheel(color::green, 1); led_effects::showKITTWheel(color::green, 1);
} }
......
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
# error Board should be either ESP8266 or ESP832 # error Board should be either ESP8266 or ESP832
#endif #endif
namespace config {
extern uint16_t csv_interval; // [s]
}
namespace csv_writer { namespace csv_writer {
extern char last_successful_write[]; extern char last_successful_write[];
void initialize(const char *sensorId); void initialize(const char *sensorId);
......
...@@ -12,12 +12,6 @@ ...@@ -12,12 +12,6 @@
#include <IotWebConf.h> #include <IotWebConf.h>
#include <IotWebConfOptionalGroup.h> #include <IotWebConfOptionalGroup.h>
namespace config {
using namespace iotwebconf;
TextTParameter<STRING_LEN> stringParam =
Builder<TextTParameter<STRING_LEN>>("stringParam").label("String param").build();
}
//TODO: Is there any conflict with SPIFFS/LittleFS? //TODO: Is there any conflict with SPIFFS/LittleFS?
//TODO: Actually use those parameters //TODO: Actually use those parameters
//TODO: Check memory consumption. Disable DEBUG info? //TODO: Check memory consumption. Disable DEBUG info?
...@@ -34,7 +28,7 @@ namespace web_config { ...@@ -34,7 +28,7 @@ namespace web_config {
IotWebConf *iotWebConf; IotWebConf *iotWebConf;
const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a05"; // -- Configuration specific key. The value should be modified if config structure was changed. const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a06"; // -- Configuration specific key. The value should be modified if config structure was changed.
using namespace iotwebconf; using namespace iotwebconf;
/** /**
...@@ -219,20 +213,11 @@ namespace web_config { ...@@ -219,20 +213,11 @@ namespace web_config {
sensor_console::defineCommand("reset_config", []() { sensor_console::defineCommand("reset_config", []() {
Serial.println(F("Resetting config...")); Serial.println(F("Resetting config..."));
//TODO: Reset every group
iotWebConf->getSystemParameterGroup()->applyDefaultValue(); iotWebConf->getSystemParameterGroup()->applyDefaultValue();
iotWebConf->saveConfig(); iotWebConf->saveConfig();
Serial.println(F("Done!")); Serial.println(F("Done!"));
}, F("(resets the complete IotWeb config)")); }, F("(resets the complete IotWeb config)"));
sensor_console::defineStringCommand("conf", [](char *new_value) {
Serial.print(F("Setting stringParam to "));
Serial.println(new_value);
strncpy(config::stringParam.value(), new_value, STRING_LEN);
Serial.println(F("Done"));
iotWebConf->saveConfig();
}, F("some_text (config setter)"));
#if !defined(AMPEL_WIFI) #if !defined(AMPEL_WIFI)
iotWebConf->loadConfig(); iotWebConf->loadConfig();
return; return;
...@@ -278,3 +263,7 @@ namespace web_config { ...@@ -278,3 +263,7 @@ namespace web_config {
}); });
} }
} }
namespace config {
uint16_t *csv_interval = &web_config::csvTimestepParam.value();
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <IotWebConfTParameter.h> #include <IotWebConfTParameter.h>
namespace config { namespace config {
extern iotwebconf::TextTParameter<STRING_LEN> stringParam; extern uint16_t *csv_interval; // [s]
} }
namespace web_config { namespace web_config {
......
...@@ -247,7 +247,7 @@ namespace web_server { ...@@ -247,7 +247,7 @@ namespace web_server {
snprintf_P(content, sizeof(content), body_template, ampel.sensorId, sensor::co2, sensor::temperature, snprintf_P(content, sizeof(content), body_template, ampel.sensorId, sensor::co2, sensor::temperature,
sensor::humidity, sensor::timestamp, config::measurement_timestep, sensor::humidity, sensor::timestamp, config::measurement_timestep,
#ifdef AMPEL_CSV #ifdef AMPEL_CSV
csv_writer::last_successful_write, config::csv_interval, csv_writer::getAvailableSpace() / 1024, csv_writer::last_successful_write, *config::csv_interval, csv_writer::getAvailableSpace() / 1024,
#endif #endif
#ifdef AMPEL_MQTT #ifdef AMPEL_MQTT
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval, mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval,
......
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