diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 33415ad1b5f99eafeb5810729d17fdb808eecc93..a6097c57bdb12ab0318f3616828e9665a816add6 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -91,7 +91,7 @@ void setup() { csv_writer::initialize(config::ampel_name()); - if (config::wifi_active) { + if (config::is_wifi_on) { wifi::defineCommands(); web_server::definePages(); wifi::tryConnection(); @@ -131,11 +131,11 @@ void loop() { checkSerialInput(); if (sensor::processData()) { - if (config::csv_active()) { + if (config::is_csv_active()) { 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); } @@ -168,7 +168,7 @@ void wifiConnected() { ntp::initialize(); - if (config::mqtt_active()) { + if (config::is_mqtt_active()) { mqtt::initialize(ampel.sensorId); } @@ -221,11 +221,11 @@ void checkFlashButton() { } void keepServicesAlive() { - if (config::wifi_active) { + if (config::is_wifi_on) { web_config::update(); if (wifi::connected()) { 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. } } diff --git a/ampel-firmware/csv_writer.cpp b/ampel-firmware/csv_writer.cpp index ada784a1218bcdf6ae1ad4e6b2c868f7ff5ec9ea..b8a5f43be1a07f3cf2b1e6a662a14f6497469cb0 100644 --- a/ampel-firmware/csv_writer.cpp +++ b/ampel-firmware/csv_writer.cpp @@ -162,7 +162,7 @@ namespace csv_writer { void logIfTimeHasCome(const char *timeStamp, const int16_t &co2, const float &temperature, const float &humidity) { unsigned long now = seconds(); - if (now - last_written_at > config::csv_interval) { + if (now - last_written_at > config::csv_timestep) { last_written_at = now; log(timeStamp, co2, temperature, humidity); } @@ -172,9 +172,9 @@ namespace csv_writer { * Callbacks for sensor commands * *****************************************************************/ 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(config::csv_interval); + Serial.print(config::csv_timestep); Serial.println("s."); config::save(); led_effects::showKITTWheel(color::green, 1); diff --git a/ampel-firmware/mqtt.cpp b/ampel-firmware/mqtt.cpp index 3f1ea47954bd0b33a8d9fcdfaa8bea8edcef47a8..f2cf3ee88acd286748f3e577b012747fe8847398 100644 --- a/ampel-firmware/mqtt.cpp +++ b/ampel-firmware/mqtt.cpp @@ -166,7 +166,7 @@ namespace mqtt { void publishIfTimeHasCome(const char *timestamp, const int16_t &co2, const float &temp, const float &hum) { // Send message via MQTT according to sending interval 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; publish(timestamp, co2, temp, hum); } @@ -184,9 +184,9 @@ namespace mqtt { * Callbacks for sensor commands * *****************************************************************/ 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(config::mqtt_sending_interval); + Serial.print(config::mqtt_sending_timestep); Serial.println("s."); config::save(); led_effects::showKITTWheel(color::green, 1); diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index b68e5baa363c7dea63d0aa8ee8a939b58f8d2665..fe7221d29053f5a3f0ebd40fe4d04af678d01d1c 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -237,7 +237,7 @@ namespace web_config { }, F("(resets the complete IotWeb config)")); sensor_console::defineIntCommand("wifi", [](int32_t onOff) { - config::wifi_active = onOff; + config::is_wifi_on = onOff; iotWebConf->saveConfig(); Serial.print(F("WiFi - ")); Serial.println(onOff ? F("On!") : F("Off!")); @@ -245,7 +245,7 @@ namespace web_config { 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!")); return; } @@ -297,7 +297,7 @@ namespace config { return web_config::iotWebConf->getWifiSsidParameter()->valueBuffer; } - char* ap_password() { + char* ampel_password() { return web_config::iotWebConf->getApPasswordParameter()->valueBuffer; } @@ -308,7 +308,7 @@ namespace config { bool &auto_calibrate_sensor = web_config::autoCalibrateParam.value(); // [true / false] 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(); void save() { web_config::iotWebConf->saveConfig(); @@ -325,20 +325,20 @@ namespace config { bool &daylight_saving_time = web_config::dstParam.value(); // CSV - bool csv_active() { + bool is_csv_active() { return web_config::csvParams.isActive(); } - uint16_t &csv_interval = web_config::csvTimestepParam.value(); + uint16_t &csv_timestep = web_config::csvTimestepParam.value(); // MQTT - bool mqtt_active() { + bool is_mqtt_active() { return web_config::mqttParams.isActive(); } char *mqtt_server = web_config::mqttServerParam.value(); char *mqtt_user = web_config::mqttUserParam.value(); char *mqtt_password = web_config::mqttPasswordParam.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 &allow_mqtt_commands = web_config::mqttCommandsParam.value(); diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index b0f3cf480b69dd3bfd4e7cfd5fd7a1d5d430e27c..f60ecb0d9c51d8ff2d6746a70ce910757c85a163 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -13,8 +13,8 @@ namespace config { char* ampel_name(); // WiFi char* selected_ssid(); - char* ap_password(); - extern bool &wifi_active; // [true / false] + char* ampel_password(); // For Access Point, and for HTML page + extern bool &is_wifi_on; // [true / false] extern uint16_t &wifi_timeout; // [s] // Sensor @@ -35,16 +35,16 @@ namespace config { extern bool &daylight_saving_time; // [true / false] //CSV - bool csv_active(); //TODO: Find better names? - extern uint16_t &csv_interval; // [s] + bool is_csv_active(); // [true / false] + extern uint16_t &csv_timestep; // [s] // MQTT - bool mqtt_active(); + bool is_mqtt_active(); // [true / false] extern char *mqtt_server; extern char *mqtt_user; extern char *mqtt_password; 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 &allow_mqtt_commands; // [true / false] diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 7a9ef8e93dbf5d39ca7ee831fc5bb92e158269a9..269042ea0dcf1cc5260d2e28698bef110e74b2a9 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -175,8 +175,8 @@ namespace web_server { * or if provided credentials match */ bool shouldBeAllowed() { - return wifi::isAccessPoint() || strcmp(config::http_user, "") == 0 || strcmp(config::ap_password(), "") == 0 - || web_config::http.authenticate(config::http_user, config::ap_password()); + return wifi::isAccessPoint() || strcmp(config::http_user, "") == 0 || strcmp(config::ampel_password(), "") == 0 + || web_config::http.authenticate(config::http_user, config::ampel_password()); } void handleWebServerRoot() { @@ -208,8 +208,8 @@ namespace web_server { // Body 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, - config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No", - mqtt::last_successful_publish, config::mqtt_sending_interval, + config::csv_timestep, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No", + mqtt::last_successful_publish, config::mqtt_sending_timestep, #if defined(ESP32) lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, config::lorawan_sending_interval,