diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index 523ee919fcc68c5cb848dd37d98bbb60f4a052bd..15a4aebc6c4a1201e06d43f5090f601885f7b558 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -114,9 +114,6 @@ void setup() { sensor::initialize(); - Serial.print("JUST A CONFIG TEST : "); - Serial.println(config::stringParam.value()); - #ifdef AMPEL_CSV csv_writer::initialize(ampel.sensorId); #endif diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp index a471e8da3d42d8f99c4f66147025e0ca4d7badba..a80f569e84265518c27a9612f792ef762695116c 100644 --- a/ampel-firmware/web_config.cpp +++ b/ampel-firmware/web_config.cpp @@ -7,6 +7,8 @@ namespace config { //TODO: Is there any conflict with SPIFFS/LittleFS? //TODO: Actually use those parameters +//TODO: Check memory consumption. Disable DEBUG info? +//TODO: Convert all strings to F-strings namespace web_config { #if defined(ESP8266) @@ -20,23 +22,15 @@ namespace web_config { IotWebConf *iotWebConf; // -- Configuration specific key. The value should be modified if config structure was changed. - // Also shouldn't be longer than - const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a01"; + const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a03"; + using namespace iotwebconf; /** * Services */ - iotwebconf::ParameterGroup serviceParams = iotwebconf::ParameterGroup("Services", "Services"); - iotwebconf::CheckboxTParameter ampelWifiParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("WiFi").label( "WiFi").defaultValue(true).build(); - iotwebconf::CheckboxTParameter ampelCSVParam = - iotwebconf::Builder<iotwebconf::CheckboxTParameter>("CSV").label("CSV").defaultValue(true).build(); - iotwebconf::CheckboxTParameter ampelMQTTParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("MQTT").label( - "MQTT").defaultValue(true).build(); - iotwebconf::CheckboxTParameter ampelLoRaWANParam = - iotwebconf::Builder<iotwebconf::CheckboxTParameter>("LoRaWAN").label("LoRaWAN").defaultValue(false).build(); //TODO: Distribute to corresponding classes, possibly with callbacks? /** @@ -66,7 +60,7 @@ namespace web_config { /** * CSV */ - iotwebconf::ParameterGroup csvParams = iotwebconf::ParameterGroup("csvs", "CSV"); + iotwebconf::OptionalParameterGroup csvParams = iotwebconf::OptionalParameterGroup("csvs", "CSV", true); iotwebconf::IntTParameter<uint16_t> csvTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>( "csv_timestep").label("CSV timestep").defaultValue(CSV_INTERVAL).min(0).step(1).build(); @@ -74,7 +68,7 @@ namespace web_config { /** * MQTT */ - iotwebconf::ParameterGroup mqttParams = iotwebconf::ParameterGroup("mqtts", "MQTT"); + iotwebconf::OptionalParameterGroup mqttParams = iotwebconf::OptionalParameterGroup("mqtts", "MQTT", true); iotwebconf::IntTParameter<uint16_t> mqttTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>( "mqtt_timestep").label("MQTT timestep").defaultValue( @@ -101,6 +95,14 @@ namespace web_config { * NTP Time */ + iotwebconf::ParameterGroup timeParams = iotwebconf::ParameterGroup("ntp", "Time server"); + iotwebconf::TextTParameter<STRING_LEN> ntpParam = iotwebconf::Builder<iotwebconf::TextTParameter< STRING_LEN>>( + "ntp_server").label("NTP Server").build(); + iotwebconf::IntTParameter<int16_t> timeOffsetParam = iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>( + "timezone").label("Timezone").defaultValue((UTC_OFFSET_IN_SECONDS) / 3600).min(-23).max(23).step(1).build(); + iotwebconf::CheckboxTParameter dstParam = iotwebconf::Builder<iotwebconf::CheckboxTParameter>("dst").label( + "Daylight Saving Time").defaultValue(false).build(); + /** * LED */ @@ -108,6 +110,12 @@ namespace web_config { /** * LoRa & Stuff */ + iotwebconf::OptionalParameterGroup loraParams = iotwebconf::OptionalParameterGroup("LoRaWan", "LoRaWan", false); + iotwebconf::IntTParameter<uint16_t> loraTimestepParam = iotwebconf::Builder<iotwebconf::IntTParameter<uint16_t>>( + "lora_timestep").label("LoRa timestep").defaultValue( + LORAWAN_SENDING_INTERVAL).min(0).step(1).defaultValue(300).build(); + + iotwebconf::OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider; void update() { iotWebConf->doLoop(); // Listen for HTTP requests from clients @@ -127,10 +135,9 @@ namespace web_config { void initialize() { iotWebConf = new IotWebConf(ampel.sensorId, &dnsServer, &http, HTTP_PASSWORD, config_version); - serviceParams.addItem(&elWifiParam); - serviceParams.addItem(&elMQTTParam); - serviceParams.addItem(&elCSVParam); - serviceParams.addItem(&elLoRaWANParam); + iotWebConf->setHtmlFormatProvider(&optionalGroupHtmlFormatProvider); + + iotWebConf->addSystemParameter(&elWifiParam); co2Params.addItem(×tepParam); co2Params.addItem(&temperatureOffsetParam); @@ -138,6 +145,10 @@ namespace web_config { co2Params.addItem(&atmosphericCO2Param); co2Params.addItem(&autoCalibrateParam); + timeParams.addItem(&ntpParam); + timeParams.addItem(&timeOffsetParam); + timeParams.addItem(&dstParam); + csvParams.addItem(&csvTimestepParam); mqttParams.addItem(&mqttTimestepParam); @@ -147,10 +158,13 @@ namespace web_config { mqttParams.addItem(&mqttUserParam); mqttParams.addItem(&mqttPasswordParam); - iotWebConf->addParameterGroup(&serviceParams); + loraParams.addItem(&loraTimestepParam); + iotWebConf->addParameterGroup(&co2Params); + iotWebConf->addParameterGroup(&timeParams); iotWebConf->addParameterGroup(&csvParams); iotWebConf->addParameterGroup(&mqttParams); + iotWebConf->addParameterGroup(&loraParams); sensor_console::defineCommand("reset_config", []() { Serial.println(F("Resetting config...")); diff --git a/ampel-firmware/web_config.h b/ampel-firmware/web_config.h index 9ded5619b084ecc9676022d7f70b374dfebe58e4..f35a874bb3628c34594eb443a43f832a4f5b3549 100644 --- a/ampel-firmware/web_config.h +++ b/ampel-firmware/web_config.h @@ -11,8 +11,11 @@ #include "config.h" +#define IOTWEBCONF_DEBUG_DISABLED // Did it change anything? + #include <IotWebConf.h> #include <IotWebConfTParameter.h> +#include <IotWebConfOptionalGroup.h> #include "util.h" //#include "sensor_console.h"