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

Config renaming

parent aeacb867
...@@ -91,7 +91,7 @@ void setup() { ...@@ -91,7 +91,7 @@ void setup() {
csv_writer::initialize(config::ampel_name()); csv_writer::initialize(config::ampel_name());
if (config::wifi_active) { if (config::is_wifi_on) {
wifi::defineCommands(); wifi::defineCommands();
web_server::definePages(); web_server::definePages();
wifi::tryConnection(); wifi::tryConnection();
...@@ -131,11 +131,11 @@ void loop() { ...@@ -131,11 +131,11 @@ void loop() {
checkSerialInput(); checkSerialInput();
if (sensor::processData()) { if (sensor::processData()) {
if (config::csv_active()) { if (config::is_csv_active()) {
csv_writer::logIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity); csv_writer::logIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity);
} }
if (config::wifi_active && config::mqtt_active()) { if (config::is_wifi_on && config::is_mqtt_active()) {
mqtt::publishIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity); mqtt::publishIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity);
} }
...@@ -168,7 +168,7 @@ void wifiConnected() { ...@@ -168,7 +168,7 @@ void wifiConnected() {
ntp::initialize(); ntp::initialize();
if (config::mqtt_active()) { if (config::is_mqtt_active()) {
mqtt::initialize(ampel.sensorId); mqtt::initialize(ampel.sensorId);
} }
...@@ -221,11 +221,11 @@ void checkFlashButton() { ...@@ -221,11 +221,11 @@ void checkFlashButton() {
} }
void keepServicesAlive() { void keepServicesAlive() {
if (config::wifi_active) { if (config::is_wifi_on) {
web_config::update(); web_config::update();
if (wifi::connected()) { if (wifi::connected()) {
ntp::update(); // NTP client has its own timer. It will connect to NTP server every 60s. ntp::update(); // NTP client has its own timer. It will connect to NTP server every 60s.
if (config::mqtt_active()) { if (config::is_mqtt_active()) {
mqtt::keepConnection(); // MQTT client has its own timer. It will keep alive every 15s. mqtt::keepConnection(); // MQTT client has its own timer. It will keep alive every 15s.
} }
} }
......
...@@ -162,7 +162,7 @@ namespace csv_writer { ...@@ -162,7 +162,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_timestep) {
last_written_at = now; last_written_at = now;
log(timeStamp, co2, temperature, humidity); log(timeStamp, co2, temperature, humidity);
} }
...@@ -172,9 +172,9 @@ namespace csv_writer { ...@@ -172,9 +172,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_timestep = 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_timestep);
Serial.println("s."); Serial.println("s.");
config::save(); config::save();
led_effects::showKITTWheel(color::green, 1); led_effects::showKITTWheel(color::green, 1);
......
...@@ -166,7 +166,7 @@ namespace mqtt { ...@@ -166,7 +166,7 @@ namespace mqtt {
void publishIfTimeHasCome(const char *timestamp, const int16_t &co2, const float &temp, const float &hum) { void publishIfTimeHasCome(const char *timestamp, const int16_t &co2, const float &temp, const float &hum) {
// Send message via MQTT according to sending interval // Send message via MQTT according to sending interval
unsigned long now = seconds(); unsigned long now = seconds();
if (now - last_sent_at > config::mqtt_sending_interval) { if (now - last_sent_at > config::mqtt_sending_timestep) {
last_sent_at = now; last_sent_at = now;
publish(timestamp, co2, temp, hum); publish(timestamp, co2, temp, hum);
} }
...@@ -184,9 +184,9 @@ namespace mqtt { ...@@ -184,9 +184,9 @@ namespace mqtt {
* Callbacks for sensor commands * * Callbacks for sensor commands *
*****************************************************************/ *****************************************************************/
void setMQTTinterval(int32_t sending_interval) { void setMQTTinterval(int32_t sending_interval) {
config::mqtt_sending_interval = sending_interval; config::mqtt_sending_timestep = sending_interval;
Serial.print(F("Setting MQTT sending interval to : ")); Serial.print(F("Setting MQTT sending interval to : "));
Serial.print(config::mqtt_sending_interval); Serial.print(config::mqtt_sending_timestep);
Serial.println("s."); Serial.println("s.");
config::save(); config::save();
led_effects::showKITTWheel(color::green, 1); led_effects::showKITTWheel(color::green, 1);
......
...@@ -237,7 +237,7 @@ namespace web_config { ...@@ -237,7 +237,7 @@ namespace web_config {
}, F("(resets the complete IotWeb config)")); }, F("(resets the complete IotWeb config)"));
sensor_console::defineIntCommand("wifi", [](int32_t onOff) { sensor_console::defineIntCommand("wifi", [](int32_t onOff) {
config::wifi_active = onOff; config::is_wifi_on = onOff;
iotWebConf->saveConfig(); iotWebConf->saveConfig();
Serial.print(F("WiFi - ")); Serial.print(F("WiFi - "));
Serial.println(onOff ? F("On!") : F("Off!")); Serial.println(onOff ? F("On!") : F("Off!"));
...@@ -245,7 +245,7 @@ namespace web_config { ...@@ -245,7 +245,7 @@ namespace web_config {
iotWebConf->loadConfig(); iotWebConf->loadConfig();
if (!config::wifi_active) { if (!config::is_wifi_on) {
Serial.println(F("Wifi is off : no access point or connection. Use 'wifi 1' to turn on again!")); Serial.println(F("Wifi is off : no access point or connection. Use 'wifi 1' to turn on again!"));
return; return;
} }
...@@ -297,7 +297,7 @@ namespace config { ...@@ -297,7 +297,7 @@ namespace config {
return web_config::iotWebConf->getWifiSsidParameter()->valueBuffer; return web_config::iotWebConf->getWifiSsidParameter()->valueBuffer;
} }
char* ap_password() { char* ampel_password() {
return web_config::iotWebConf->getApPasswordParameter()->valueBuffer; return web_config::iotWebConf->getApPasswordParameter()->valueBuffer;
} }
...@@ -308,7 +308,7 @@ namespace config { ...@@ -308,7 +308,7 @@ namespace config {
bool &auto_calibrate_sensor = web_config::autoCalibrateParam.value(); // [true / false] bool &auto_calibrate_sensor = web_config::autoCalibrateParam.value(); // [true / false]
float &temperature_offset = web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant. float &temperature_offset = web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant.
bool &wifi_active = web_config::ampelWifiParam.value(); bool &is_wifi_on = web_config::ampelWifiParam.value();
uint16_t &wifi_timeout = web_config::wifiTimeoutParam.value(); uint16_t &wifi_timeout = web_config::wifiTimeoutParam.value();
void save() { void save() {
web_config::iotWebConf->saveConfig(); web_config::iotWebConf->saveConfig();
...@@ -325,20 +325,20 @@ namespace config { ...@@ -325,20 +325,20 @@ namespace config {
bool &daylight_saving_time = web_config::dstParam.value(); bool &daylight_saving_time = web_config::dstParam.value();
// CSV // CSV
bool csv_active() { bool is_csv_active() {
return web_config::csvParams.isActive(); return web_config::csvParams.isActive();
} }
uint16_t &csv_interval = web_config::csvTimestepParam.value(); uint16_t &csv_timestep = web_config::csvTimestepParam.value();
// MQTT // MQTT
bool mqtt_active() { bool is_mqtt_active() {
return web_config::mqttParams.isActive(); return web_config::mqttParams.isActive();
} }
char *mqtt_server = web_config::mqttServerParam.value(); char *mqtt_server = web_config::mqttServerParam.value();
char *mqtt_user = web_config::mqttUserParam.value(); char *mqtt_user = web_config::mqttUserParam.value();
char *mqtt_password = web_config::mqttPasswordParam.value(); char *mqtt_password = web_config::mqttPasswordParam.value();
uint16_t &mqtt_port = web_config::mqttPortParam.value(); uint16_t &mqtt_port = web_config::mqttPortParam.value();
uint16_t &mqtt_sending_interval = web_config::mqttTimestepParam.value(); uint16_t &mqtt_sending_timestep = web_config::mqttTimestepParam.value();
bool &mqtt_encryption = web_config::mqttEncryptionParam.value(); bool &mqtt_encryption = web_config::mqttEncryptionParam.value();
bool &allow_mqtt_commands = web_config::mqttCommandsParam.value(); bool &allow_mqtt_commands = web_config::mqttCommandsParam.value();
......
...@@ -13,8 +13,8 @@ namespace config { ...@@ -13,8 +13,8 @@ namespace config {
char* ampel_name(); char* ampel_name();
// WiFi // WiFi
char* selected_ssid(); char* selected_ssid();
char* ap_password(); char* ampel_password(); // For Access Point, and for HTML page
extern bool &wifi_active; // [true / false] extern bool &is_wifi_on; // [true / false]
extern uint16_t &wifi_timeout; // [s] extern uint16_t &wifi_timeout; // [s]
// Sensor // Sensor
...@@ -35,16 +35,16 @@ namespace config { ...@@ -35,16 +35,16 @@ namespace config {
extern bool &daylight_saving_time; // [true / false] extern bool &daylight_saving_time; // [true / false]
//CSV //CSV
bool csv_active(); //TODO: Find better names? bool is_csv_active(); // [true / false]
extern uint16_t &csv_interval; // [s] extern uint16_t &csv_timestep; // [s]
// MQTT // MQTT
bool mqtt_active(); bool is_mqtt_active(); // [true / false]
extern char *mqtt_server; extern char *mqtt_server;
extern char *mqtt_user; extern char *mqtt_user;
extern char *mqtt_password; extern char *mqtt_password;
extern uint16_t &mqtt_port; extern uint16_t &mqtt_port;
extern uint16_t &mqtt_sending_interval; // [s] extern uint16_t &mqtt_sending_timestep; // [s]
extern bool &mqtt_encryption; // [true / false] extern bool &mqtt_encryption; // [true / false]
extern bool &allow_mqtt_commands; // [true / false] extern bool &allow_mqtt_commands; // [true / false]
......
...@@ -175,8 +175,8 @@ namespace web_server { ...@@ -175,8 +175,8 @@ namespace web_server {
* or if provided credentials match * or if provided credentials match
*/ */
bool shouldBeAllowed() { bool shouldBeAllowed() {
return wifi::isAccessPoint() || strcmp(config::http_user, "") == 0 || strcmp(config::ap_password(), "") == 0 return wifi::isAccessPoint() || strcmp(config::http_user, "") == 0 || strcmp(config::ampel_password(), "") == 0
|| web_config::http.authenticate(config::http_user, config::ap_password()); || web_config::http.authenticate(config::http_user, config::ampel_password());
} }
void handleWebServerRoot() { void handleWebServerRoot() {
...@@ -208,8 +208,8 @@ namespace web_server { ...@@ -208,8 +208,8 @@ namespace web_server {
// Body // Body
snprintf_P(content, sizeof(content), body_template, config::ampel_name(), sensor::co2, sensor::temperature, snprintf_P(content, sizeof(content), body_template, config::ampel_name(), sensor::co2, sensor::temperature,
sensor::humidity, sensor::timestamp, config::measurement_timestep, csv_writer::last_successful_write, sensor::humidity, sensor::timestamp, config::measurement_timestep, csv_writer::last_successful_write,
config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No", config::csv_timestep, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No",
mqtt::last_successful_publish, config::mqtt_sending_interval, mqtt::last_successful_publish, config::mqtt_sending_timestep,
#if defined(ESP32) #if defined(ESP32)
lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission,
config::lorawan_sending_interval, config::lorawan_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