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

Config renaming

parent aeacb867
......@@ -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.
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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();
......
......@@ -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]
......
......@@ -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,
......
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